From 304d23c839e22f4f2eeabc20d7fe09db468af6af Mon Sep 17 00:00:00 2001 From: SvyatoslavArtymovych Date: Fri, 21 Apr 2023 17:27:20 +0300 Subject: [PATCH] migrations --- migrations/versions/02f6f2ebad1b_.py | 199 +++++++++++++++++++++++ migrations/versions/766427519c34_init.py | 40 ----- 2 files changed, 199 insertions(+), 40 deletions(-) create mode 100644 migrations/versions/02f6f2ebad1b_.py delete mode 100644 migrations/versions/766427519c34_init.py diff --git a/migrations/versions/02f6f2ebad1b_.py b/migrations/versions/02f6f2ebad1b_.py new file mode 100644 index 0000000..609f6fd --- /dev/null +++ b/migrations/versions/02f6f2ebad1b_.py @@ -0,0 +1,199 @@ +"""empty message + +Revision ID: 02f6f2ebad1b +Revises: +Create Date: 2023-04-21 17:26:06.003994 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = '02f6f2ebad1b' +down_revision = None +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.create_table('tags', + sa.Column('name', sa.String(length=32), nullable=False), + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=True), + sa.Column('is_deleted', sa.Boolean(), nullable=True), + sa.PrimaryKeyConstraint('id'), + sa.UniqueConstraint('name') + ) + op.create_table('users', + sa.Column('username', sa.String(length=60), nullable=False), + sa.Column('password_hash', sa.String(length=255), nullable=True), + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=True), + sa.Column('is_deleted', sa.Boolean(), nullable=True), + sa.PrimaryKeyConstraint('id'), + sa.UniqueConstraint('username') + ) + op.create_table('books', + sa.Column('label', sa.String(length=1024), nullable=False), + sa.Column('user_id', sa.Integer(), nullable=True), + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=True), + sa.Column('is_deleted', sa.Boolean(), nullable=True), + sa.ForeignKeyConstraint(['user_id'], ['users.id'], ), + sa.PrimaryKeyConstraint('id') + ) + op.create_table('book_contributors', + sa.Column('role', sa.Enum('UNKNOWN', 'MODERATOR', 'EDITOR', name='roles'), nullable=True), + sa.Column('user_id', sa.Integer(), nullable=True), + sa.Column('book_id', sa.Integer(), nullable=True), + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=True), + sa.Column('is_deleted', sa.Boolean(), nullable=True), + sa.ForeignKeyConstraint(['book_id'], ['books.id'], ), + sa.ForeignKeyConstraint(['user_id'], ['users.id'], ), + sa.PrimaryKeyConstraint('id') + ) + op.create_table('book_versions', + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('semver', sa.String(length=1024), nullable=False), + sa.Column('exported', sa.Boolean(), nullable=True), + sa.Column('updated_at', sa.DateTime(), nullable=True), + sa.Column('derivative_id', sa.Integer(), nullable=True), + sa.Column('book_id', sa.Integer(), nullable=True), + sa.Column('created_at', sa.DateTime(), nullable=True), + sa.Column('is_deleted', sa.Boolean(), nullable=True), + sa.ForeignKeyConstraint(['book_id'], ['books.id'], ), + sa.ForeignKeyConstraint(['derivative_id'], ['book_versions.id'], ), + sa.PrimaryKeyConstraint('id') + ) + op.create_table('books_stars', + sa.Column('user_id', sa.Integer(), nullable=True), + sa.Column('book_id', sa.Integer(), nullable=True), + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=True), + sa.Column('is_deleted', sa.Boolean(), nullable=True), + sa.ForeignKeyConstraint(['book_id'], ['books.id'], ), + sa.ForeignKeyConstraint(['user_id'], ['users.id'], ), + sa.PrimaryKeyConstraint('id') + ) + op.create_table('collections', + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('label', sa.String(length=1024), nullable=False), + sa.Column('about', sa.Text(), nullable=False), + sa.Column('is_root', sa.Boolean(), nullable=True), + sa.Column('is_leaf', sa.Boolean(), nullable=True), + sa.Column('version_id', sa.Integer(), nullable=True), + sa.Column('parrent_id', sa.Integer(), nullable=True), + sa.Column('created_at', sa.DateTime(), nullable=True), + sa.Column('is_deleted', sa.Boolean(), nullable=True), + sa.ForeignKeyConstraint(['parrent_id'], ['collections.id'], ), + sa.ForeignKeyConstraint(['version_id'], ['book_versions.id'], ), + sa.PrimaryKeyConstraint('id') + ) + op.create_table('sections', + sa.Column('label', sa.String(length=1024), nullable=False), + sa.Column('about', sa.Text(), nullable=True), + sa.Column('collection_id', sa.Integer(), nullable=True), + sa.Column('user_id', sa.Integer(), nullable=True), + sa.Column('version_id', sa.Integer(), nullable=True), + sa.Column('selected_interpretation_id', sa.Integer(), nullable=True), + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=True), + sa.Column('is_deleted', sa.Boolean(), nullable=True), + sa.ForeignKeyConstraint(['collection_id'], ['collections.id'], ), + sa.ForeignKeyConstraint(['user_id'], ['users.id'], ), + sa.ForeignKeyConstraint(['version_id'], ['book_versions.id'], ), + sa.PrimaryKeyConstraint('id') + ) + op.create_table('interpretations', + sa.Column('label', sa.String(length=1024), nullable=False), + sa.Column('text', sa.Text(), nullable=False), + sa.Column('marked', sa.Boolean(), nullable=True), + sa.Column('user_id', sa.Integer(), nullable=True), + sa.Column('section_id', sa.Integer(), nullable=True), + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=True), + sa.Column('is_deleted', sa.Boolean(), nullable=True), + sa.ForeignKeyConstraint(['section_id'], ['sections.id'], ), + sa.ForeignKeyConstraint(['user_id'], ['users.id'], ), + sa.PrimaryKeyConstraint('id') + ) + op.create_table('comments', + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('text', sa.Text(), nullable=False), + sa.Column('marked', sa.Boolean(), nullable=True), + sa.Column('included_with_interpreation', sa.Boolean(), nullable=True), + sa.Column('user_id', sa.Integer(), nullable=True), + sa.Column('parrent_id', sa.Integer(), nullable=True), + sa.Column('interpretation_id', sa.Integer(), nullable=True), + sa.Column('created_at', sa.DateTime(), nullable=True), + sa.Column('is_deleted', sa.Boolean(), nullable=True), + sa.ForeignKeyConstraint(['interpretation_id'], ['interpretations.id'], ), + sa.ForeignKeyConstraint(['parrent_id'], ['comments.id'], ), + sa.ForeignKeyConstraint(['user_id'], ['users.id'], ), + sa.PrimaryKeyConstraint('id') + ) + op.create_table('interpretation_tags', + sa.Column('tag_id', sa.Integer(), nullable=True), + sa.Column('interpretation_id', sa.Integer(), nullable=True), + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=True), + sa.Column('is_deleted', sa.Boolean(), nullable=True), + sa.ForeignKeyConstraint(['interpretation_id'], ['interpretations.id'], ), + sa.ForeignKeyConstraint(['tag_id'], ['tags.id'], ), + sa.PrimaryKeyConstraint('id') + ) + op.create_table('interpretation_votes', + sa.Column('user_id', sa.Integer(), nullable=True), + sa.Column('interpretation_id', sa.Integer(), nullable=True), + sa.Column('possitive', sa.Boolean(), nullable=True), + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=True), + sa.Column('is_deleted', sa.Boolean(), nullable=True), + sa.ForeignKeyConstraint(['interpretation_id'], ['interpretations.id'], ), + sa.ForeignKeyConstraint(['user_id'], ['users.id'], ), + sa.PrimaryKeyConstraint('id') + ) + op.create_table('comment_tags', + sa.Column('tag_id', sa.Integer(), nullable=True), + sa.Column('comment_id', sa.Integer(), nullable=True), + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=True), + sa.Column('is_deleted', sa.Boolean(), nullable=True), + sa.ForeignKeyConstraint(['comment_id'], ['comments.id'], ), + sa.ForeignKeyConstraint(['tag_id'], ['tags.id'], ), + sa.PrimaryKeyConstraint('id') + ) + op.create_table('comment_votes', + sa.Column('user_id', sa.Integer(), nullable=True), + sa.Column('comment_id', sa.Integer(), nullable=True), + sa.Column('possitive', sa.Boolean(), nullable=True), + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=True), + sa.Column('is_deleted', sa.Boolean(), nullable=True), + sa.ForeignKeyConstraint(['comment_id'], ['comments.id'], ), + sa.ForeignKeyConstraint(['user_id'], ['users.id'], ), + sa.PrimaryKeyConstraint('id') + ) + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.drop_table('comment_votes') + op.drop_table('comment_tags') + op.drop_table('interpretation_votes') + op.drop_table('interpretation_tags') + op.drop_table('comments') + op.drop_table('interpretations') + op.drop_table('sections') + op.drop_table('collections') + op.drop_table('books_stars') + op.drop_table('book_versions') + op.drop_table('book_contributors') + op.drop_table('books') + op.drop_table('users') + op.drop_table('tags') + # ### end Alembic commands ### diff --git a/migrations/versions/766427519c34_init.py b/migrations/versions/766427519c34_init.py deleted file mode 100644 index f64c7e3..0000000 --- a/migrations/versions/766427519c34_init.py +++ /dev/null @@ -1,40 +0,0 @@ -"""init - -Revision ID: 766427519c34 -Revises: -Create Date: 2023-04-07 19:36:58.671750 - -""" -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '766427519c34' -down_revision = None -branch_labels = None -depends_on = None - - -def upgrade(): - # ### commands auto generated by Alembic - please adjust! ### - op.create_table('users', - sa.Column('id', sa.Integer(), nullable=False), - sa.Column('username', sa.String(length=60), nullable=False), - sa.Column('email', sa.String(length=255), nullable=False), - sa.Column('password_hash', sa.String(length=255), nullable=True), - sa.Column('activated', sa.Boolean(), nullable=True), - sa.Column('created_at', sa.DateTime(), nullable=True), - sa.Column('unique_id', sa.String(length=36), nullable=True), - sa.Column('reset_password_uid', sa.String(length=64), nullable=True), - sa.PrimaryKeyConstraint('id'), - sa.UniqueConstraint('email'), - sa.UniqueConstraint('username') - ) - # ### end Alembic commands ### - - -def downgrade(): - # ### commands auto generated by Alembic - please adjust! ### - op.drop_table('users') - # ### end Alembic commands ###