Alembic installed and activated. Poems table added

This commit is contained in:
2023-07-23 22:52:31 +03:00
committed by Dmitry Gantimurov
parent b06306a20b
commit d97ca1c43f
13 changed files with 378 additions and 16 deletions

1
migrations/README Normal file
View File

@ -0,0 +1 @@
Generic single-database configuration.

85
migrations/env.py Normal file
View File

@ -0,0 +1,85 @@
from logging.config import fileConfig
from sqlalchemy import engine_from_config
from sqlalchemy import pool
from alembic import context
from back import db, base
# this is the Alembic Config object, which provides
# access to the values within the .ini file in use.
config = context.config
# Interpret the config file for Python logging.
# This line sets up loggers basically.
if config.config_file_name is not None:
fileConfig(config.config_file_name)
# add your model's MetaData object here
# for 'autogenerate' support
# from myapp import mymodel
# target_metadata = mymodel.Base.metadata
target_metadata = base.Base.metadata
# target_metadata = None
# other values from the config, defined by the needs of env.py,
# can be acquired:
# my_important_option = config.get_main_option("my_important_option")
# ... etc.
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")
url = config.get_main_option(db.SQLALCHEMY_DATABASE_URL)
context.configure(
url=url,
target_metadata=target_metadata,
literal_binds=True,
dialect_opts={"paramstyle": "named"},
)
with context.begin_transaction():
context.run_migrations()
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.
"""
configuration = config.get_section(config.config_ini_section)
configuration['sqlalchemy.url'] = db.SQLALCHEMY_DATABASE_URL
connectable = engine_from_config(
configuration,
prefix="sqlalchemy.",
poolclass=pool.NullPool,
)
with connectable.connect() as connection:
context.configure(
connection=connection, target_metadata=target_metadata
)
with context.begin_transaction():
context.run_migrations()
if context.is_offline_mode():
run_migrations_offline()
else:
run_migrations_online()

24
migrations/script.py.mako Normal file
View File

@ -0,0 +1,24 @@
"""${message}
Revision ID: ${up_revision}
Revises: ${down_revision | comma,n}
Create Date: ${create_date}
"""
from alembic import op
import sqlalchemy as sa
${imports if imports else ""}
# revision identifiers, used by Alembic.
revision = ${repr(up_revision)}
down_revision = ${repr(down_revision)}
branch_labels = ${repr(branch_labels)}
depends_on = ${repr(depends_on)}
def upgrade():
${upgrades if upgrades else "pass"}
def downgrade():
${downgrades if downgrades else "pass"}

View File

@ -0,0 +1,28 @@
"""first
Revision ID: 0006eca30e2c
Revises:
Create Date: 2023-07-23 22:32:43.496939
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '0006eca30e2c'
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 ###

View File

@ -0,0 +1,34 @@
"""Poems table added
Revision ID: 18001c2231e3
Revises: 33c5716276b5
Create Date: 2023-07-23 22:50:16.055961
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '18001c2231e3'
down_revision = '33c5716276b5'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('poems',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('poem_text', sa.String(), nullable=True),
sa.PrimaryKeyConstraint('id')
)
op.create_index(op.f('ix_poems_id'), 'poems', ['id'], unique=False)
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_index(op.f('ix_poems_id'), table_name='poems')
op.drop_table('poems')
# ### end Alembic commands ###

View File

@ -0,0 +1,70 @@
"""Try to make alembic see models
Revision ID: 33c5716276b5
Revises: 0006eca30e2c
Create Date: 2023-07-23 22:42:07.532395
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '33c5716276b5'
down_revision = '0006eca30e2c'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('announcements',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('user_id', sa.Integer(), nullable=True),
sa.Column('name', sa.String(), nullable=True),
sa.Column('category', sa.String(), nullable=True),
sa.Column('best_by', sa.Integer(), nullable=True),
sa.Column('address', sa.String(), nullable=True),
sa.Column('longtitude', sa.Integer(), nullable=True),
sa.Column('latitude', sa.Integer(), nullable=True),
sa.Column('description', sa.String(), nullable=True),
sa.Column('src', sa.String(), nullable=True),
sa.Column('metro', sa.String(), nullable=True),
sa.Column('trashId', sa.Integer(), nullable=True),
sa.Column('booked_by', sa.Integer(), nullable=True),
sa.PrimaryKeyConstraint('id')
)
op.create_index(op.f('ix_announcements_id'), 'announcements', ['id'], unique=False)
op.create_table('trashboxes',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(), nullable=True),
sa.Column('address', sa.String(), nullable=True),
sa.Column('latitude', sa.Integer(), nullable=True),
sa.Column('longtitude', sa.Integer(), nullable=True),
sa.Column('category', sa.String(), nullable=True),
sa.PrimaryKeyConstraint('id')
)
op.create_index(op.f('ix_trashboxes_id'), 'trashboxes', ['id'], unique=False)
op.create_table('users',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('phone', sa.Integer(), nullable=True),
sa.Column('email', sa.String(), nullable=True),
sa.Column('password', sa.String(), nullable=True),
sa.Column('hashed_password', sa.String(), nullable=True),
sa.Column('name', sa.String(), nullable=True),
sa.Column('surname', sa.String(), nullable=True),
sa.PrimaryKeyConstraint('id')
)
op.create_index(op.f('ix_users_id'), 'users', ['id'], unique=True)
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_index(op.f('ix_users_id'), table_name='users')
op.drop_table('users')
op.drop_index(op.f('ix_trashboxes_id'), table_name='trashboxes')
op.drop_table('trashboxes')
op.drop_index(op.f('ix_announcements_id'), table_name='announcements')
op.drop_table('announcements')
# ### end Alembic commands ###