diff options
author | 2020-08-25 13:23:32 +0100 | |
---|---|---|
committer | 2020-08-25 13:23:32 +0100 | |
commit | 21f0a8abafde86d27033d72b817bb2aad4938292 (patch) | |
tree | 242bb799d7cf4f8e467824d24f331c10fcefdaae /alembic/versions | |
parent | Add config files to gitignore (diff) |
Add Alembic
Diffstat (limited to 'alembic/versions')
5 files changed, 178 insertions, 0 deletions
diff --git a/alembic/versions/38085c8f1099_enable_cascade_deletion_for_messages.py b/alembic/versions/38085c8f1099_enable_cascade_deletion_for_messages.py new file mode 100644 index 0000000..522d96a --- /dev/null +++ b/alembic/versions/38085c8f1099_enable_cascade_deletion_for_messages.py @@ -0,0 +1,34 @@ +"""enable cascade deletion for messages + +Revision ID: 38085c8f1099 +Revises: abc065ff2fb3 +Create Date: 2020-08-25 13:00:21.629836 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = '38085c8f1099' +down_revision = 'abc065ff2fb3' +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.drop_constraint('messages_author_id_fkey', 'messages', type_='foreignkey') + op.drop_constraint('messages_channel_id_fkey', 'messages', type_='foreignkey') + op.create_foreign_key(None, 'messages', 'users', ['author_id'], ['id'], ondelete='CASCADE') + op.create_foreign_key(None, 'messages', 'channels', ['channel_id'], ['id'], ondelete='CASCADE') + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.drop_constraint(None, 'messages', type_='foreignkey') + op.drop_constraint(None, 'messages', type_='foreignkey') + op.create_foreign_key('messages_channel_id_fkey', 'messages', 'channels', ['channel_id'], ['id']) + op.create_foreign_key('messages_author_id_fkey', 'messages', 'users', ['author_id'], ['id']) + # ### end Alembic commands ### diff --git a/alembic/versions/4d293b37634c_initial_migration.py b/alembic/versions/4d293b37634c_initial_migration.py new file mode 100644 index 0000000..23e7ea4 --- /dev/null +++ b/alembic/versions/4d293b37634c_initial_migration.py @@ -0,0 +1,28 @@ +"""initial migration + +Revision ID: 4d293b37634c +Revises: +Create Date: 2020-08-25 03:09:13.565389 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = '4d293b37634c' +down_revision = None +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + pass + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + pass + # ### end Alembic commands ### diff --git a/alembic/versions/6b52b1e7680b_add_channel_categories.py b/alembic/versions/6b52b1e7680b_add_channel_categories.py new file mode 100644 index 0000000..bdbcde1 --- /dev/null +++ b/alembic/versions/6b52b1e7680b_add_channel_categories.py @@ -0,0 +1,34 @@ +"""add channel categories + +Revision ID: 6b52b1e7680b +Revises: d42a9cc66591 +Create Date: 2020-08-25 05:10:43.945126 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = '6b52b1e7680b' +down_revision = 'd42a9cc66591' +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.create_table('categories', + sa.Column('id', sa.BigInteger(), nullable=False), + sa.Column('name', sa.String(), nullable=False), + sa.PrimaryKeyConstraint('id') + ) + op.add_column('channels', sa.Column('category_id', sa.BigInteger(), nullable=True)) + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.drop_column('channels', 'category_id') + op.drop_table('categories') + # ### end Alembic commands ### diff --git a/alembic/versions/abc065ff2fb3_add_bot_column_to_user_table.py b/alembic/versions/abc065ff2fb3_add_bot_column_to_user_table.py new file mode 100644 index 0000000..9c53999 --- /dev/null +++ b/alembic/versions/abc065ff2fb3_add_bot_column_to_user_table.py @@ -0,0 +1,28 @@ +"""add bot column to user table + +Revision ID: abc065ff2fb3 +Revises: 6b52b1e7680b +Create Date: 2020-08-25 05:24:01.730596 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = 'abc065ff2fb3' +down_revision = '6b52b1e7680b' +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.add_column('users', sa.Column('bot', sa.Boolean(), nullable=True)) + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.drop_column('users', 'bot') + # ### end Alembic commands ### diff --git a/alembic/versions/d42a9cc66591_add_channels_users_and_messages_table.py b/alembic/versions/d42a9cc66591_add_channels_users_and_messages_table.py new file mode 100644 index 0000000..0ed3728 --- /dev/null +++ b/alembic/versions/d42a9cc66591_add_channels_users_and_messages_table.py @@ -0,0 +1,54 @@ +"""add channels, users and messages table + +Revision ID: d42a9cc66591 +Revises: 4d293b37634c +Create Date: 2020-08-25 03:10:21.282787 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = 'd42a9cc66591' +down_revision = '4d293b37634c' +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.create_table('channels', + sa.Column('id', sa.BigInteger(), nullable=False), + sa.Column('name', sa.String(), nullable=False), + sa.Column('is_staff', sa.Boolean(), nullable=False), + sa.PrimaryKeyConstraint('id') + ) + op.create_table('users', + sa.Column('id', sa.BigInteger(), nullable=False), + sa.Column('name', sa.String(), nullable=False), + sa.Column('avatar_hash', sa.String(), nullable=True), + sa.Column('joined_at', sa.DateTime(), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.Column('is_staff', sa.Boolean(), nullable=False), + sa.Column('opt_out', sa.Boolean(), nullable=True), + sa.PrimaryKeyConstraint('id') + ) + op.create_table('messages', + sa.Column('id', sa.BigInteger(), nullable=False), + sa.Column('channel_id', sa.BigInteger(), nullable=True), + sa.Column('author_id', sa.BigInteger(), nullable=True), + sa.Column('created_at', sa.DateTime(), nullable=True), + sa.ForeignKeyConstraint(['author_id'], ['users.id'], ), + sa.ForeignKeyConstraint(['channel_id'], ['channels.id'], ), + sa.PrimaryKeyConstraint('id') + ) + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.drop_table('messages') + op.drop_table('users') + op.drop_table('channels') + # ### end Alembic commands ### |