summaryrefslogtreecommitdiff
path: root/alembic/versions
diff options
context:
space:
mode:
authorRasmus Luha <rasmus.luha@gmail.com>2022-02-24 02:57:29 +0200
committerRasmus Luha <rasmus.luha@gmail.com>2022-02-24 02:57:29 +0200
commit3ce694bbebb9c24606e83f8923ca8055b7c9c63d (patch)
tree79bdc75a28eadabb18fb65978f0dec914eea546d /alembic/versions
parentf1ab105a7620160c16d7c91bdf3ca1cff6deef7c (diff)
Added Alembic stuff
Diffstat (limited to 'alembic/versions')
-rw-r--r--alembic/versions/19d57d527c14_create_posts_table.py27
-rw-r--r--alembic/versions/4fa455e8771b_auto_add_votes_table.py34
-rw-r--r--alembic/versions/7fb31859972f_add_revision_table.py33
-rw-r--r--alembic/versions/e68b0c5f7380_add_foreign_key_to_posts_table.py29
-rw-r--r--alembic/versions/f18f4db81d80_add_content_column_to_posts_table.py26
-rw-r--r--alembic/versions/f60bfe68b20f_add_other_posts_columns.py30
6 files changed, 179 insertions, 0 deletions
diff --git a/alembic/versions/19d57d527c14_create_posts_table.py b/alembic/versions/19d57d527c14_create_posts_table.py
new file mode 100644
index 0000000..8550646
--- /dev/null
+++ b/alembic/versions/19d57d527c14_create_posts_table.py
@@ -0,0 +1,27 @@
+"""create posts table
+
+Revision ID: 19d57d527c14
+Revises:
+Create Date: 2022-02-24 01:18:04.684095
+
+"""
+from alembic import op
+import sqlalchemy as sa
+
+
+# revision identifiers, used by Alembic.
+revision = '19d57d527c14'
+down_revision = None
+branch_labels = None
+depends_on = None
+
+
+def upgrade():
+ op.create_table("posts", sa.Column('id', sa.Integer(), nullable=False, primary_key=True ),
+ sa.Column("title", sa.String(), nullable=False) )
+ pass
+
+
+def downgrade():
+ op.drop_table('posts')
+ pass
diff --git a/alembic/versions/4fa455e8771b_auto_add_votes_table.py b/alembic/versions/4fa455e8771b_auto_add_votes_table.py
new file mode 100644
index 0000000..6c60f85
--- /dev/null
+++ b/alembic/versions/4fa455e8771b_auto_add_votes_table.py
@@ -0,0 +1,34 @@
+"""auto-add Votes table
+
+Revision ID: 4fa455e8771b
+Revises: f60bfe68b20f
+Create Date: 2022-02-24 02:53:06.350609
+
+"""
+from alembic import op
+import sqlalchemy as sa
+
+
+# revision identifiers, used by Alembic.
+revision = '4fa455e8771b'
+down_revision = 'f60bfe68b20f'
+branch_labels = None
+depends_on = None
+
+
+def upgrade():
+ # ### commands auto generated by Alembic - please adjust! ###
+ op.create_table('votes',
+ sa.Column('user_id', sa.Integer(), nullable=False),
+ sa.Column('post_id', sa.Integer(), nullable=False),
+ sa.ForeignKeyConstraint(['post_id'], ['posts.id'], ondelete='CASCADE'),
+ sa.ForeignKeyConstraint(['user_id'], ['users.id'], ondelete='CASCADE'),
+ sa.PrimaryKeyConstraint('user_id', 'post_id')
+ )
+ # ### end Alembic commands ###
+
+
+def downgrade():
+ # ### commands auto generated by Alembic - please adjust! ###
+ op.drop_table('votes')
+ # ### end Alembic commands ###
diff --git a/alembic/versions/7fb31859972f_add_revision_table.py b/alembic/versions/7fb31859972f_add_revision_table.py
new file mode 100644
index 0000000..440e695
--- /dev/null
+++ b/alembic/versions/7fb31859972f_add_revision_table.py
@@ -0,0 +1,33 @@
+"""add revision table
+
+Revision ID: 7fb31859972f
+Revises: f18f4db81d80
+Create Date: 2022-02-24 02:14:33.592965
+
+"""
+from alembic import op
+import sqlalchemy as sa
+
+
+# revision identifiers, used by Alembic.
+revision = '7fb31859972f'
+down_revision = 'f18f4db81d80'
+branch_labels = None
+depends_on = None
+
+
+def upgrade():
+ op.create_table("users",
+ sa.Column("id", sa.Integer(), nullable=False),
+ sa.Column("email", sa.String(), nullable=False),
+ sa.Column("password", sa.String(), nullable=False),
+ sa.Column("created_at", sa.TIMESTAMP(timezone=True), server_default=sa.text('now()'), nullable=False),
+ sa.PrimaryKeyConstraint("id"),
+ sa.UniqueConstraint("email")
+ )
+ pass
+
+
+def downgrade():
+ op.drop_table("users")
+ pass
diff --git a/alembic/versions/e68b0c5f7380_add_foreign_key_to_posts_table.py b/alembic/versions/e68b0c5f7380_add_foreign_key_to_posts_table.py
new file mode 100644
index 0000000..4ef704a
--- /dev/null
+++ b/alembic/versions/e68b0c5f7380_add_foreign_key_to_posts_table.py
@@ -0,0 +1,29 @@
+"""Add foreign-key to posts table
+
+Revision ID: e68b0c5f7380
+Revises: 7fb31859972f
+Create Date: 2022-02-24 02:21:51.623836
+
+"""
+from alembic import op
+import sqlalchemy as sa
+
+
+# revision identifiers, used by Alembic.
+revision = 'e68b0c5f7380'
+down_revision = '7fb31859972f'
+branch_labels = None
+depends_on = None
+
+
+def upgrade():
+ op.add_column("posts", sa.Column("owner_id", sa.Integer(), nullable=False) )
+ op.create_foreign_key("post_users_fk", source_table="posts", referent_table="users",
+ local_cols=["owner_id"], remote_cols=["id"], ondelete="CASCADE")
+ pass
+
+
+def downgrade():
+ op.drop_constraint("post_users_fk", table_name="posts")
+ op.drop_column("posts", "owner_id")
+ pass
diff --git a/alembic/versions/f18f4db81d80_add_content_column_to_posts_table.py b/alembic/versions/f18f4db81d80_add_content_column_to_posts_table.py
new file mode 100644
index 0000000..a783bf5
--- /dev/null
+++ b/alembic/versions/f18f4db81d80_add_content_column_to_posts_table.py
@@ -0,0 +1,26 @@
+"""add content column to posts table
+
+Revision ID: f18f4db81d80
+Revises: 19d57d527c14
+Create Date: 2022-02-24 02:03:54.409749
+
+"""
+from alembic import op
+import sqlalchemy as sa
+
+
+# revision identifiers, used by Alembic.
+revision = 'f18f4db81d80'
+down_revision = '19d57d527c14'
+branch_labels = None
+depends_on = None
+
+
+def upgrade():
+ op.add_column("posts", sa.Column("content", sa.String(), nullable=False) )
+ pass
+
+
+def downgrade():
+ op.drop_column("posts", "content")
+ pass
diff --git a/alembic/versions/f60bfe68b20f_add_other_posts_columns.py b/alembic/versions/f60bfe68b20f_add_other_posts_columns.py
new file mode 100644
index 0000000..0f2c369
--- /dev/null
+++ b/alembic/versions/f60bfe68b20f_add_other_posts_columns.py
@@ -0,0 +1,30 @@
+"""add other posts columns
+
+Revision ID: f60bfe68b20f
+Revises: e68b0c5f7380
+Create Date: 2022-02-24 02:26:37.946997
+
+"""
+from alembic import op
+import sqlalchemy as sa
+
+
+# revision identifiers, used by Alembic.
+revision = 'f60bfe68b20f'
+down_revision = 'e68b0c5f7380'
+branch_labels = None
+depends_on = None
+
+
+def upgrade():
+ op.add_column("posts", sa.Column("published", sa.Boolean(), nullable=False,
+ server_default="TRUE"),)
+ op.add_column("posts", sa.Column("created_at", sa.TIMESTAMP(timezone=True), nullable=False,
+ server_default=sa.text("NOW()")),)
+ pass
+
+
+def downgrade():
+ op.drop_column("posts", "published")
+ op.drop_column("posts", "created_at")
+ pass