diff --git a/.circleci/config.yml b/.circleci/config.yml index caf42e4..4bc95d2 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -90,7 +90,7 @@ workflows: - Heroku: context: Heroku requires: - - Build + - Docker - Docker: context: Docker requires: diff --git a/migrations/env.py b/migrations/env.py index e486088..79b8174 100644 --- a/migrations/env.py +++ b/migrations/env.py @@ -35,12 +35,15 @@ target_metadata = current_app.extensions['migrate'].db.metadata def run_migrations_offline(): """Run migrations in 'offline' mode. + This configures the context with just a URL and not an Engine, though an Engine is acceptable here as well. By skipping the Engine creation we don't even need a DBAPI to be available. + Calls to context.execute() here emit the given string to the script output. + """ url = config.get_main_option("sqlalchemy.url") context.configure( @@ -53,8 +56,10 @@ def run_migrations_offline(): def run_migrations_online(): """Run migrations in 'online' mode. + In this scenario we need to create an Engine and associate a connection with the context. + """ # this callback is used to prevent an auto-migration from being generated @@ -88,4 +93,4 @@ def run_migrations_online(): if context.is_offline_mode(): run_migrations_offline() else: - run_migrations_online() \ No newline at end of file + run_migrations_online() diff --git a/migrations/versions/2267f00a4594_.py b/migrations/versions/2267f00a4594_.py new file mode 100644 index 0000000..3b7f481 --- /dev/null +++ b/migrations/versions/2267f00a4594_.py @@ -0,0 +1,101 @@ +"""empty message + +Revision ID: 2267f00a4594 +Revises: +Create Date: 2020-01-04 15:20:33.461410 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = '2267f00a4594' +down_revision = None +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.create_table('tags', + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('tagname', sa.String(length=100), nullable=True), + sa.PrimaryKeyConstraint('id') + ) + op.create_table('users', + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('username', sa.String(length=80), nullable=False), + sa.Column('email', sa.String(length=100), nullable=False), + sa.Column('password', sa.Binary(), nullable=True), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.Column('updated_at', sa.DateTime(), nullable=False), + sa.Column('bio', sa.String(length=300), nullable=True), + sa.Column('image', sa.String(length=120), nullable=True), + sa.PrimaryKeyConstraint('id'), + sa.UniqueConstraint('email'), + sa.UniqueConstraint('username') + ) + op.create_table('userprofile', + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('user_id', sa.Integer(), nullable=False), + sa.ForeignKeyConstraint(['user_id'], ['users.id'], ), + sa.PrimaryKeyConstraint('id'), + sa.UniqueConstraint('user_id') + ) + op.create_table('article', + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('slug', sa.Text(), nullable=True), + sa.Column('title', sa.String(length=100), nullable=False), + sa.Column('description', sa.Text(), nullable=False), + sa.Column('body', sa.Text(), nullable=True), + sa.Column('createdAt', sa.DateTime(), nullable=False), + sa.Column('updatedAt', sa.DateTime(), nullable=False), + sa.Column('author_id', sa.Integer(), nullable=False), + sa.ForeignKeyConstraint(['author_id'], ['userprofile.id'], ), + sa.PrimaryKeyConstraint('id'), + sa.UniqueConstraint('slug') + ) + op.create_table('followers_assoc', + sa.Column('follower', sa.Integer(), nullable=True), + sa.Column('followed_by', sa.Integer(), nullable=True), + sa.ForeignKeyConstraint(['followed_by'], ['userprofile.user_id'], ), + sa.ForeignKeyConstraint(['follower'], ['userprofile.user_id'], ) + ) + op.create_table('comment', + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('body', sa.Text(), nullable=True), + sa.Column('createdAt', sa.DateTime(), nullable=False), + sa.Column('updatedAt', sa.DateTime(), nullable=False), + sa.Column('author_id', sa.Integer(), nullable=False), + sa.Column('article_id', sa.Integer(), nullable=False), + sa.ForeignKeyConstraint(['article_id'], ['article.id'], ), + sa.ForeignKeyConstraint(['author_id'], ['userprofile.id'], ), + sa.PrimaryKeyConstraint('id') + ) + op.create_table('favoritor_assoc', + sa.Column('favoriter', sa.Integer(), nullable=True), + sa.Column('favorited_article', sa.Integer(), nullable=True), + sa.ForeignKeyConstraint(['favorited_article'], ['article.id'], ), + sa.ForeignKeyConstraint(['favoriter'], ['userprofile.id'], ) + ) + op.create_table('tag_assoc', + sa.Column('tag', sa.Integer(), nullable=True), + sa.Column('article', sa.Integer(), nullable=True), + sa.ForeignKeyConstraint(['article'], ['article.id'], ), + sa.ForeignKeyConstraint(['tag'], ['tags.id'], ) + ) + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.drop_table('tag_assoc') + op.drop_table('favoritor_assoc') + op.drop_table('comment') + op.drop_table('followers_assoc') + op.drop_table('article') + op.drop_table('userprofile') + op.drop_table('users') + op.drop_table('tags') + # ### end Alembic commands ###