Skip to content

Commit 4a705f9

Browse files
committed
squash migrations, use timestamp rev id
1 parent c32e7e4 commit 4a705f9

22 files changed

Lines changed: 207 additions & 704 deletions

sopy/ext/sqlalchemy.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from datetime import datetime
2+
13
from flask import current_app, g
24
from flask_alembic import Alembic
35
from flask_sqlalchemy import Model as BaseModel, SQLAlchemy as BaseSQLAlchemy
@@ -61,10 +63,17 @@ def get_unique(cls, **kwargs):
6163
return o
6264

6365

66+
def rev_id():
67+
offset = datetime(2017, 12, 13, 21)
68+
now = datetime.utcnow()
69+
return str(int((now - offset).total_seconds()))
70+
71+
6472
class SQLAlchemy(BaseSQLAlchemy):
6573
def __init__(self, **kwargs):
6674
super().__init__(**kwargs)
6775
self.alembic = Alembic()
76+
self.alembic.rev_id = rev_id
6877

6978
def init_app(self, app):
7079
super(SQLAlchemy, self).init_app(app)

sopy/migrations/1051_squash.py

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
"""squash
2+
3+
Revision ID: 1051
4+
Revises:
5+
Create Date: 2017-12-13 13:17:31.742850
6+
"""
7+
8+
from alembic import op
9+
import sqlalchemy as sa
10+
11+
12+
revision = '1051'
13+
down_revision = None
14+
branch_labels = ('default',)
15+
depends_on = None
16+
17+
18+
def upgrade():
19+
op.create_table('group',
20+
sa.Column('id', sa.Integer(), nullable=False),
21+
sa.Column('name', sa.String(), nullable=False),
22+
sa.PrimaryKeyConstraint('id', name=op.f('pk_group')),
23+
sa.UniqueConstraint('name', name=op.f('uq_group_name'))
24+
)
25+
op.create_table('se_question',
26+
sa.Column('id', sa.Integer(), autoincrement=False, nullable=False),
27+
sa.Column('title', sa.String(), nullable=False),
28+
sa.Column('body', sa.String(), nullable=False),
29+
sa.Column('link', sa.String(), nullable=False),
30+
sa.PrimaryKeyConstraint('id', name=op.f('pk_se_question'))
31+
)
32+
op.create_table('se_user',
33+
sa.Column('id', sa.Integer(), autoincrement=False, nullable=False),
34+
sa.Column('display_name', sa.String(), nullable=False),
35+
sa.Column('profile_image', sa.String(), nullable=False),
36+
sa.Column('profile_link', sa.String(), nullable=False),
37+
sa.Column('reputation', sa.Integer(), nullable=False),
38+
sa.PrimaryKeyConstraint('id', name=op.f('pk_se_user'))
39+
)
40+
op.create_table('tag',
41+
sa.Column('id', sa.Integer(), nullable=False),
42+
sa.Column('name', sa.String(), nullable=False),
43+
sa.PrimaryKeyConstraint('id', name=op.f('pk_tag')),
44+
sa.UniqueConstraint('name', name=op.f('uq_tag_name'))
45+
)
46+
op.create_table('transcript',
47+
sa.Column('id', sa.Integer(), nullable=False),
48+
sa.Column('title', sa.String(), nullable=False),
49+
sa.Column('ts', sa.DateTime(), nullable=False),
50+
sa.Column('body', sa.String(), nullable=False),
51+
sa.PrimaryKeyConstraint('id', name=op.f('pk_transcript'))
52+
)
53+
op.create_table('chat_message',
54+
sa.Column('id', sa.Integer(), autoincrement=False, nullable=False),
55+
sa.Column('room_id', sa.Integer(), nullable=False),
56+
sa.Column('user_id', sa.Integer(), nullable=False),
57+
sa.Column('ts', sa.DateTime(), nullable=False),
58+
sa.Column('content', sa.String(), nullable=False),
59+
sa.Column('rendered', sa.Boolean(), nullable=False),
60+
sa.Column('stars', sa.Integer(), nullable=False),
61+
sa.ForeignKeyConstraint(['user_id'], ['se_user.id'], name=op.f('fk_chat_message_user_id_se_user')),
62+
sa.PrimaryKeyConstraint('id', name=op.f('pk_chat_message'))
63+
)
64+
op.create_table('group_group',
65+
sa.Column('member_id', sa.Integer(), nullable=False),
66+
sa.Column('group_id', sa.Integer(), nullable=False),
67+
sa.ForeignKeyConstraint(['group_id'], ['group.id'], name=op.f('fk_group_group_group_id_group')),
68+
sa.ForeignKeyConstraint(['member_id'], ['group.id'], name=op.f('fk_group_group_member_id_group')),
69+
sa.PrimaryKeyConstraint('member_id', 'group_id', name=op.f('pk_group_group'))
70+
)
71+
op.create_table('se_question_tag',
72+
sa.Column('se_question_id', sa.Integer(), nullable=False),
73+
sa.Column('tag_id', sa.Integer(), nullable=False),
74+
sa.ForeignKeyConstraint(['se_question_id'], ['se_question.id'], name=op.f('fk_se_question_tag_se_question_id_se_question')),
75+
sa.ForeignKeyConstraint(['tag_id'], ['tag.id'], name=op.f('fk_se_question_tag_tag_id_tag')),
76+
sa.PrimaryKeyConstraint('se_question_id', 'tag_id', name=op.f('pk_se_question_tag'))
77+
)
78+
op.create_table('user',
79+
sa.Column('id', sa.Integer(), nullable=False),
80+
sa.Column('superuser', sa.Boolean(), nullable=False),
81+
sa.ForeignKeyConstraint(['id'], ['se_user.id'], name=op.f('fk_user_id_se_user')),
82+
sa.PrimaryKeyConstraint('id', name=op.f('pk_user'))
83+
)
84+
op.create_table('canon_item',
85+
sa.Column('id', sa.Integer(), nullable=False),
86+
sa.Column('title', sa.String(), nullable=False),
87+
sa.Column('excerpt', sa.String(), nullable=False),
88+
sa.Column('body', sa.String(), nullable=False),
89+
sa.Column('draft', sa.Boolean(), nullable=False),
90+
sa.Column('community', sa.Boolean(), nullable=False),
91+
sa.Column('updated_by_id', sa.Integer(), nullable=False),
92+
sa.ForeignKeyConstraint(['updated_by_id'], ['user.id'], name=op.f('fk_canon_item_updated_by_id_user')),
93+
sa.PrimaryKeyConstraint('id', name=op.f('pk_canon_item'))
94+
)
95+
op.create_table('salad',
96+
sa.Column('id', sa.Integer(), nullable=False),
97+
sa.Column('term', sa.String(), nullable=False),
98+
sa.Column('definition', sa.String(), nullable=False),
99+
sa.Column('position', sa.Integer(), nullable=False),
100+
sa.Column('updated_by_id', sa.Integer(), nullable=False),
101+
sa.ForeignKeyConstraint(['updated_by_id'], ['user.id'], name=op.f('fk_salad_updated_by_id_user')),
102+
sa.PrimaryKeyConstraint('id', name=op.f('pk_salad')),
103+
sa.UniqueConstraint('term', name=op.f('uq_salad_term'))
104+
)
105+
op.create_table('transcript_message',
106+
sa.Column('transcript_id', sa.Integer(), nullable=False),
107+
sa.Column('message_id', sa.Integer(), nullable=False),
108+
sa.ForeignKeyConstraint(['message_id'], ['chat_message.id'], name=op.f('fk_transcript_message_message_id_chat_message')),
109+
sa.ForeignKeyConstraint(['transcript_id'], ['transcript.id'], name=op.f('fk_transcript_message_transcript_id_transcript')),
110+
sa.PrimaryKeyConstraint('transcript_id', 'message_id', name=op.f('pk_transcript_message'))
111+
)
112+
op.create_table('user_group',
113+
sa.Column('user_id', sa.Integer(), nullable=False),
114+
sa.Column('group_id', sa.Integer(), nullable=False),
115+
sa.ForeignKeyConstraint(['group_id'], ['group.id'], name=op.f('fk_user_group_group_id_group')),
116+
sa.ForeignKeyConstraint(['user_id'], ['user.id'], name=op.f('fk_user_group_user_id_user')),
117+
sa.PrimaryKeyConstraint('user_id', 'group_id', name=op.f('pk_user_group'))
118+
)
119+
op.create_table('wiki_page',
120+
sa.Column('id', sa.Integer(), nullable=False),
121+
sa.Column('title', sa.String(), nullable=False),
122+
sa.Column('body', sa.String(), nullable=False),
123+
sa.Column('updated', sa.DateTime(), nullable=False),
124+
sa.Column('draft', sa.Boolean(), nullable=False),
125+
sa.Column('community', sa.Boolean(), nullable=False),
126+
sa.Column('author_id', sa.Integer(), nullable=False),
127+
sa.Column('redirect_id', sa.Integer(), nullable=True),
128+
sa.ForeignKeyConstraint(['author_id'], ['user.id'], name=op.f('fk_wiki_page_author_id_user')),
129+
sa.ForeignKeyConstraint(['redirect_id'], ['wiki_page.id'], name=op.f('fk_wiki_page_redirect_id_wiki_page')),
130+
sa.PrimaryKeyConstraint('id', name=op.f('pk_wiki_page')),
131+
sa.UniqueConstraint('title', name=op.f('uq_wiki_page_title'))
132+
)
133+
op.create_table('canon_item_se_question',
134+
sa.Column('canon_item_id', sa.Integer(), nullable=False),
135+
sa.Column('se_question_id', sa.Integer(), nullable=False),
136+
sa.ForeignKeyConstraint(['canon_item_id'], ['canon_item.id'], name=op.f('fk_canon_item_se_question_canon_item_id_canon_item')),
137+
sa.ForeignKeyConstraint(['se_question_id'], ['se_question.id'], name=op.f('fk_canon_item_se_question_se_question_id_se_question')),
138+
sa.PrimaryKeyConstraint('canon_item_id', 'se_question_id', name=op.f('pk_canon_item_se_question'))
139+
)
140+
op.create_table('canon_item_tag',
141+
sa.Column('canon_item_id', sa.Integer(), nullable=False),
142+
sa.Column('tag_id', sa.Integer(), nullable=False),
143+
sa.ForeignKeyConstraint(['canon_item_id'], ['canon_item.id'], name=op.f('fk_canon_item_tag_canon_item_id_canon_item')),
144+
sa.ForeignKeyConstraint(['tag_id'], ['tag.id'], name=op.f('fk_canon_item_tag_tag_id_tag')),
145+
sa.PrimaryKeyConstraint('canon_item_id', 'tag_id', name=op.f('pk_canon_item_tag'))
146+
)
147+
148+
149+
def downgrade():
150+
op.drop_table('canon_item_tag')
151+
op.drop_table('canon_item_se_question')
152+
op.drop_table('wiki_page')
153+
op.drop_table('user_group')
154+
op.drop_table('transcript_message')
155+
op.drop_table('salad')
156+
op.drop_table('canon_item')
157+
op.drop_table('user')
158+
op.drop_table('se_question_tag')
159+
op.drop_table('group_group')
160+
op.drop_table('chat_message')
161+
op.drop_table('transcript')
162+
op.drop_table('tag')
163+
op.drop_table('se_user')
164+
op.drop_table('se_question')
165+
op.drop_table('group')

sopy/migrations/1377a5a0097_community_user.py

Lines changed: 0 additions & 56 deletions
This file was deleted.

sopy/migrations/14aa0a5af3a_auth.py

Lines changed: 0 additions & 39 deletions
This file was deleted.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
"""rename constraints
2+
3+
Revision ID: 1532
4+
Revises: 1051
5+
Create Date: 2017-12-13 13:25:32.236544
6+
"""
7+
8+
from alembic import op
9+
import sqlalchemy as sa
10+
11+
12+
revision = '1532'
13+
down_revision = '1051'
14+
branch_labels = ()
15+
depends_on = None
16+
17+
18+
def upgrade():
19+
op.create_unique_constraint(op.f('uq_group_name'), 'group', ['name'])
20+
op.drop_constraint('group_name_key', 'group', type_='unique')
21+
op.create_unique_constraint(op.f('uq_salad_term'), 'salad', ['term'])
22+
op.drop_constraint('salad_term_key', 'salad', type_='unique')
23+
op.create_unique_constraint(op.f('uq_tag_name'), 'tag', ['name'])
24+
op.drop_constraint('tag_name_key', 'tag', type_='unique')
25+
26+
27+
def downgrade():
28+
op.create_unique_constraint('tag_name_key', 'tag', ['name'])
29+
op.drop_constraint(op.f('uq_tag_name'), 'tag', type_='unique')
30+
op.create_unique_constraint('salad_term_key', 'salad', ['term'])
31+
op.drop_constraint(op.f('uq_salad_term'), 'salad', type_='unique')
32+
op.create_unique_constraint('group_name_key', 'group', ['name'])
33+
op.drop_constraint(op.f('uq_group_name'), 'group', type_='unique')

sopy/migrations/1914e1c7a03_group_hierarchy.py

Lines changed: 0 additions & 24 deletions
This file was deleted.

sopy/migrations/1f5a6a1a28c_add_profile_image.py

Lines changed: 0 additions & 23 deletions
This file was deleted.

0 commit comments

Comments
 (0)