version control db
This commit is contained in:
parent
948281dbfb
commit
abc2e66c29
11 changed files with 278 additions and 76 deletions
1
alembic/README
Normal file
1
alembic/README
Normal file
|
@ -0,0 +1 @@
|
|||
Generic single-database configuration.
|
79
alembic/env.py
Normal file
79
alembic/env.py
Normal file
|
@ -0,0 +1,79 @@
|
|||
from logging.config import fileConfig
|
||||
|
||||
from sqlalchemy import engine_from_config
|
||||
from sqlalchemy import pool
|
||||
|
||||
from alembic import context
|
||||
|
||||
# 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
|
||||
from src.models import TableNotification, TableSteamItem, TableGiveaway, Base
|
||||
target_metadata = Base.metadata
|
||||
|
||||
# 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")
|
||||
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.
|
||||
|
||||
"""
|
||||
connectable = engine_from_config(
|
||||
config.get_section(config.config_ini_section),
|
||||
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
alembic/script.py.mako
Normal file
24
alembic/script.py.mako
Normal 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"}
|
70
alembic/versions/2022_05_19-15_50_19-1da33402b659_init.py
Normal file
70
alembic/versions/2022_05_19-15_50_19-1da33402b659_init.py
Normal file
|
@ -0,0 +1,70 @@
|
|||
"""init
|
||||
|
||||
Revision ID: 1da33402b659
|
||||
Revises:
|
||||
Create Date: 2022-05-19 15:50:19.539401
|
||||
|
||||
"""
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '1da33402b659'
|
||||
down_revision = None
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.create_table('notification',
|
||||
sa.Column('id', sa.Integer(), nullable=False),
|
||||
sa.Column('type', sa.String(length=50), nullable=False),
|
||||
sa.Column('message', sa.String(length=300), nullable=False),
|
||||
sa.Column('medium', sa.String(length=50), nullable=False),
|
||||
sa.Column('success', sa.Boolean(), nullable=False),
|
||||
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('(CURRENT_TIMESTAMP)'),
|
||||
nullable=True),
|
||||
sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('(CURRENT_TIMESTAMP)'),
|
||||
nullable=True),
|
||||
sa.PrimaryKeyConstraint('id')
|
||||
)
|
||||
op.create_table('steam_item',
|
||||
sa.Column('steam_id', sa.String(length=15), nullable=False),
|
||||
sa.Column('game_name', sa.String(length=200), nullable=False),
|
||||
sa.Column('steam_url', sa.String(length=100), nullable=False),
|
||||
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('(CURRENT_TIMESTAMP)'),
|
||||
nullable=True),
|
||||
sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('(CURRENT_TIMESTAMP)'),
|
||||
nullable=True),
|
||||
sa.PrimaryKeyConstraint('steam_id')
|
||||
)
|
||||
op.create_table('giveaway',
|
||||
sa.Column('giveaway_id', sa.String(length=10), nullable=False),
|
||||
sa.Column('steam_id', sa.Integer(), nullable=False),
|
||||
sa.Column('giveaway_uri', sa.String(length=200), nullable=False),
|
||||
sa.Column('user', sa.String(length=40), nullable=False),
|
||||
sa.Column('giveaway_created_at', sa.DateTime(timezone=True), nullable=False),
|
||||
sa.Column('giveaway_ended_at', sa.DateTime(timezone=True), nullable=False),
|
||||
sa.Column('cost', sa.Integer(), nullable=False),
|
||||
sa.Column('copies', sa.Integer(), nullable=False),
|
||||
sa.Column('contributor_level', sa.Integer(), nullable=False),
|
||||
sa.Column('entered', sa.Boolean(), nullable=False),
|
||||
sa.Column('won', sa.Boolean(), nullable=False),
|
||||
sa.Column('game_entries', sa.Integer(), nullable=False),
|
||||
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('(CURRENT_TIMESTAMP)'),
|
||||
nullable=True),
|
||||
sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('(CURRENT_TIMESTAMP)'),
|
||||
nullable=True),
|
||||
sa.ForeignKeyConstraint(['steam_id'], ['steam_item.steam_id'], ),
|
||||
sa.PrimaryKeyConstraint('giveaway_id', 'steam_id')
|
||||
)
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.drop_table('giveaway')
|
||||
op.drop_table('steam_item')
|
||||
op.drop_table('notification')
|
||||
# ### end Alembic commands ###
|
Loading…
Add table
Add a link
Reference in a new issue