-
Notifications
You must be signed in to change notification settings - Fork 0
/
migration.txt
98 lines (80 loc) · 3.45 KB
/
migration.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
!!!!!! PASTE BELOW VERSION !!!!!!!
from alembic import op
import sqlalchemy as sa
import os
environment = os.getenv("FLASK_ENV")
SCHEMA = os.environ.get("SCHEMA")
!!! ADD IN REVISION STUFF !!!
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('users',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('first_name', sa.String(length=50), nullable=False),
sa.Column('last_name', sa.String(length=50), nullable=False),
sa.Column('age', sa.Integer(), nullable=False),
sa.Column('username', sa.String(length=50), nullable=False),
sa.Column('email', sa.String(length=50), nullable=False),
sa.Column('hashed_password', sa.String(), nullable=False),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('email'),
sa.UniqueConstraint('username')
)
if environment == "production":
op.execute(f"ALTER TABLE users SET SCHEMA {SCHEMA};")
op.create_table('albums',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('user_id', sa.Integer(), nullable=True),
sa.Column('title', sa.String(), nullable=False),
sa.Column('created_at', sa.Date(), nullable=False),
sa.ForeignKeyConstraint(['user_id'], ['users.id'], ),
sa.PrimaryKeyConstraint('id')
)
if environment == "production":
op.execute(f"ALTER TABLE albums SET SCHEMA {SCHEMA};")
op.create_table('posts',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('owner_id', sa.Integer(), nullable=True),
sa.Column('album_id', sa.Integer(), nullable=True),
sa.Column('title', sa.String(length=50), nullable=False),
sa.Column('photo_url', sa.String(), nullable=False),
sa.Column('description', sa.String(length=1000), nullable=False),
sa.Column('tag', sa.String(length=50), nullable=False),
sa.Column('created_at', sa.Date(), nullable=False),
sa.ForeignKeyConstraint(['album_id'], ['albums.id'], ),
sa.ForeignKeyConstraint(['owner_id'], ['users.id'], ),
sa.PrimaryKeyConstraint('id')
)
if environment == "production":
op.execute(f"ALTER TABLE posts SET SCHEMA {SCHEMA};")
op.create_table('comments',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('user_id', sa.Integer(), nullable=False),
sa.Column('post_id', sa.Integer(), nullable=False),
sa.Column('comment', sa.String(length=1000), nullable=False),
sa.Column('created_at', sa.Date(), nullable=False),
sa.ForeignKeyConstraint(['post_id'], ['posts.id'], ),
sa.ForeignKeyConstraint(['user_id'], ['users.id'], ),
sa.PrimaryKeyConstraint('id')
)
if environment == "production":
op.execute(f"ALTER TABLE comments SET SCHEMA {SCHEMA};")
op.create_table('favorites',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('user_id', sa.Integer(), nullable=False),
sa.Column('post_id', sa.Integer(), nullable=False),
sa.Column('created_at', sa.Date(), nullable=False),
sa.ForeignKeyConstraint(['post_id'], ['posts.id'], ),
sa.ForeignKeyConstraint(['user_id'], ['users.id'], ),
sa.PrimaryKeyConstraint('id'),
)
if environment == "production":
op.execute(f"ALTER TABLE favorites SET SCHEMA {SCHEMA};")
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('favorites')
op.drop_table('comments')
op.drop_table('posts')
op.drop_table('albums')
op.drop_table('users')
# ### end Alembic commands ###