0.2.0 initial commit
This commit is contained in:
commit
6f67d125af
38 changed files with 2051 additions and 0 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 xefyl import models
|
||||
target_metadata = models.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() -> None:
|
||||
"""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() -> None:
|
||||
"""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() -> None:
|
||||
${upgrades if upgrades else "pass"}
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
${downgrades if downgrades else "pass"}
|
||||
77
alembic/versions/3bfaa1b74794_.py
Normal file
77
alembic/versions/3bfaa1b74794_.py
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
"""empty message
|
||||
|
||||
Revision ID: 3bfaa1b74794
|
||||
Revises:
|
||||
Create Date: 2023-11-19 15:50:38.211123
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '3bfaa1b74794'
|
||||
down_revision = None
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.create_table('image',
|
||||
sa.Column('id', sa.BigInteger(), nullable=False),
|
||||
sa.Column('type', sa.SmallInteger(), nullable=True),
|
||||
sa.Column('format', sa.SmallInteger(), nullable=True),
|
||||
sa.Column('name', sa.String(length=256), nullable=True),
|
||||
sa.Column('hash', sa.String(length=256), nullable=True),
|
||||
sa.Column('date', sa.DateTime(), nullable=True),
|
||||
sa.Column('size', sa.BigInteger(), nullable=True),
|
||||
sa.Column('pathname', sa.String(length=8192), nullable=True),
|
||||
sa.PrimaryKeyConstraint('id'),
|
||||
sa.UniqueConstraint('pathname')
|
||||
)
|
||||
op.create_index(op.f('ix_image_date'), 'image', ['date'], unique=False)
|
||||
op.create_index(op.f('ix_image_hash'), 'image', ['hash'], unique=False)
|
||||
op.create_index(op.f('ix_image_name'), 'image', ['name'], unique=False)
|
||||
op.create_index(op.f('ix_image_type'), 'image', ['type'], unique=False)
|
||||
op.create_table('video',
|
||||
sa.Column('id', sa.BigInteger(), nullable=False),
|
||||
sa.Column('type', sa.SmallInteger(), nullable=True),
|
||||
sa.Column('format', sa.SmallInteger(), nullable=True),
|
||||
sa.Column('name', sa.String(length=256), nullable=True),
|
||||
sa.Column('duration', sa.Float(), nullable=True),
|
||||
sa.Column('date', sa.DateTime(), nullable=True),
|
||||
sa.Column('size', sa.BigInteger(), nullable=True),
|
||||
sa.Column('pathname', sa.String(length=8192), nullable=True),
|
||||
sa.PrimaryKeyConstraint('id'),
|
||||
sa.UniqueConstraint('pathname')
|
||||
)
|
||||
op.create_index(op.f('ix_video_date'), 'video', ['date'], unique=False)
|
||||
op.create_index(op.f('ix_video_duration'), 'video', ['duration'], unique=False)
|
||||
op.create_index(op.f('ix_video_name'), 'video', ['name'], unique=False)
|
||||
op.create_index(op.f('ix_video_type'), 'video', ['type'], unique=False)
|
||||
op.create_table('imagetag',
|
||||
sa.Column('id', sa.BigInteger(), nullable=False),
|
||||
sa.Column('image_id', sa.BigInteger(), nullable=True),
|
||||
sa.Column('name', sa.String(length=64), nullable=True),
|
||||
sa.ForeignKeyConstraint(['image_id'], ['image.id'], ),
|
||||
sa.PrimaryKeyConstraint('id'),
|
||||
sa.UniqueConstraint('image_id', 'name')
|
||||
)
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.drop_table('imagetag')
|
||||
op.drop_index(op.f('ix_video_type'), table_name='video')
|
||||
op.drop_index(op.f('ix_video_name'), table_name='video')
|
||||
op.drop_index(op.f('ix_video_duration'), table_name='video')
|
||||
op.drop_index(op.f('ix_video_date'), table_name='video')
|
||||
op.drop_table('video')
|
||||
op.drop_index(op.f('ix_image_type'), table_name='image')
|
||||
op.drop_index(op.f('ix_image_name'), table_name='image')
|
||||
op.drop_index(op.f('ix_image_hash'), table_name='image')
|
||||
op.drop_index(op.f('ix_image_date'), table_name='image')
|
||||
op.drop_table('image')
|
||||
# ### end Alembic commands ###
|
||||
94
alembic/versions/63d014f73934_.py
Normal file
94
alembic/versions/63d014f73934_.py
Normal file
|
|
@ -0,0 +1,94 @@
|
|||
"""empty message
|
||||
|
||||
Revision ID: 63d014f73934
|
||||
Revises: 3bfaa1b74794
|
||||
Create Date: 2023-12-02 21:50:41.457594
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '63d014f73934'
|
||||
down_revision = '3bfaa1b74794'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.create_table('user',
|
||||
sa.Column('id', sa.BigInteger(), nullable=False),
|
||||
sa.Column('username', sa.String(length=30), nullable=True),
|
||||
sa.Column('display_name', sa.String(length=64), nullable=True),
|
||||
sa.Column('passhash', sa.String(length=256), nullable=True),
|
||||
sa.Column('joined_at', sa.String(length=256), nullable=True),
|
||||
sa.PrimaryKeyConstraint('id'),
|
||||
sa.UniqueConstraint('username')
|
||||
)
|
||||
op.create_table('imagecollection',
|
||||
sa.Column('id', sa.BigInteger(), nullable=False),
|
||||
sa.Column('name', sa.String(length=128), nullable=False),
|
||||
sa.Column('owner_id', sa.BigInteger(), nullable=True),
|
||||
sa.Column('description', sa.String(length=4096), nullable=True),
|
||||
sa.ForeignKeyConstraint(['owner_id'], ['user.id'], ),
|
||||
sa.PrimaryKeyConstraint('id')
|
||||
)
|
||||
op.create_table('imageincollection',
|
||||
sa.Column('image_id', sa.BigInteger(), nullable=False),
|
||||
sa.Column('collection_id', sa.BigInteger(), nullable=False),
|
||||
sa.Column('since', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=True),
|
||||
sa.ForeignKeyConstraint(['collection_id'], ['imagecollection.id'], ),
|
||||
sa.ForeignKeyConstraint(['image_id'], ['image.id'], ),
|
||||
sa.PrimaryKeyConstraint('image_id', 'collection_id')
|
||||
)
|
||||
op.create_index(op.f('ix_imageincollection_since'), 'imageincollection', ['since'], unique=False)
|
||||
op.drop_index('idx_60001_image_date', table_name='image')
|
||||
op.drop_index('idx_60001_image_hash', table_name='image')
|
||||
op.drop_index('idx_60001_image_name', table_name='image')
|
||||
op.drop_index('idx_60001_image_pathname', table_name='image')
|
||||
op.drop_index('idx_60001_image_type', table_name='image')
|
||||
op.create_index(op.f('ix_image_date'), 'image', ['date'], unique=False)
|
||||
op.create_index(op.f('ix_image_hash'), 'image', ['hash'], unique=False)
|
||||
op.create_index(op.f('ix_image_name'), 'image', ['name'], unique=False)
|
||||
op.create_index(op.f('ix_image_type'), 'image', ['type'], unique=False)
|
||||
op.create_unique_constraint(None, 'image', ['pathname'])
|
||||
op.drop_index('idx_59995_imagetag_image_id', table_name='imagetag')
|
||||
op.drop_index('idx_59995_imagetag_image_id_name', table_name='imagetag')
|
||||
op.create_unique_constraint(None, 'imagetag', ['image_id', 'name'])
|
||||
op.create_foreign_key(None, 'imagetag', 'image', ['image_id'], ['id'])
|
||||
op.create_index(op.f('ix_video_date'), 'video', ['date'], unique=False)
|
||||
op.create_index(op.f('ix_video_duration'), 'video', ['duration'], unique=False)
|
||||
op.create_index(op.f('ix_video_name'), 'video', ['name'], unique=False)
|
||||
op.create_index(op.f('ix_video_type'), 'video', ['type'], unique=False)
|
||||
op.create_unique_constraint(None, 'video', ['pathname'])
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.drop_constraint(None, 'video', type_='unique')
|
||||
op.drop_index(op.f('ix_video_type'), table_name='video')
|
||||
op.drop_index(op.f('ix_video_name'), table_name='video')
|
||||
op.drop_index(op.f('ix_video_duration'), table_name='video')
|
||||
op.drop_index(op.f('ix_video_date'), table_name='video')
|
||||
op.drop_constraint(None, 'imagetag', type_='foreignkey')
|
||||
op.drop_constraint(None, 'imagetag', type_='unique')
|
||||
op.create_index('idx_59995_imagetag_image_id_name', 'imagetag', ['image_id', 'name'], unique=False)
|
||||
op.create_index('idx_59995_imagetag_image_id', 'imagetag', ['image_id'], unique=False)
|
||||
op.drop_constraint(None, 'image', type_='unique')
|
||||
op.drop_index(op.f('ix_image_type'), table_name='image')
|
||||
op.drop_index(op.f('ix_image_name'), table_name='image')
|
||||
op.drop_index(op.f('ix_image_hash'), table_name='image')
|
||||
op.drop_index(op.f('ix_image_date'), table_name='image')
|
||||
op.create_index('idx_60001_image_type', 'image', ['type'], unique=False)
|
||||
op.create_index('idx_60001_image_pathname', 'image', ['pathname'], unique=False)
|
||||
op.create_index('idx_60001_image_name', 'image', ['name'], unique=False)
|
||||
op.create_index('idx_60001_image_hash', 'image', ['hash'], unique=False)
|
||||
op.create_index('idx_60001_image_date', 'image', ['date'], unique=False)
|
||||
op.drop_index(op.f('ix_imageincollection_since'), table_name='imageincollection')
|
||||
op.drop_table('imageincollection')
|
||||
op.drop_table('imagecollection')
|
||||
op.drop_table('user')
|
||||
# ### end Alembic commands ###
|
||||
28
alembic/versions/fbf0bcc3368a_.py
Normal file
28
alembic/versions/fbf0bcc3368a_.py
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
"""empty message
|
||||
|
||||
Revision ID: fbf0bcc3368a
|
||||
Revises: 63d014f73934
|
||||
Create Date: 2023-12-31 16:10:00.055273
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = 'fbf0bcc3368a'
|
||||
down_revision = '63d014f73934'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
pass
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
pass
|
||||
# ### end Alembic commands ###
|
||||
Loading…
Add table
Add a link
Reference in a new issue