git reimport

This commit is contained in:
2019-03-15 15:02:19 +04:00
commit 742797309a
90 changed files with 4411 additions and 0 deletions

1
alembic/README Normal file
View File

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

83
alembic/env.py Normal file
View File

@@ -0,0 +1,83 @@
from __future__ import with_statement
from logging.config import fileConfig
from alembic import context
from sqlalchemy import engine_from_config, pool
from main import read_config
from zvk.bot.bot import Bot
from zvk.util.db import DBBase
# 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.
fileConfig(config.config_file_name)
# add your model's MetaData object here
# for 'autogenerate' support
# from myapp import mymodel
# target_metadata = mymodel.Base.metadata
bot = Bot(config=read_config())
db = bot.db
target_metadata = DBBase.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, render_as_batch=True)
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,
render_as_batch=True
)
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
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 @@
"""init
Revision ID: 7cc70eff053e
Revises:
Create Date: 2018-10-19 23:23:23.765848
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '7cc70eff053e'
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,39 @@
"""Message
Revision ID: fbc835042266
Revises: 7cc70eff053e
Create Date: 2018-10-19 23:24:04.641316
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = 'fbc835042266'
down_revision = '7cc70eff053e'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('Message_auto',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('message_id', sa.Integer(), nullable=False),
sa.Column('from_id', sa.Integer(), nullable=False),
sa.Column('to_id', sa.Integer(), nullable=False),
sa.Column('flags', sa.Integer(), nullable=False),
sa.Column('timestamp', sa.Integer(), nullable=False),
sa.Column('attachments', sa.String(), nullable=False),
sa.Column('random_id', sa.Integer(), nullable=False),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('message_id')
)
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('Message_auto')
# ### end Alembic commands ###

View File

@@ -0,0 +1,33 @@
"""VKEvent
Revision ID: cbb2ece35ae0
Revises: fbc835042266
Create Date: 2018-10-20 01:10:54.532015
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = 'cbb2ece35ae0'
down_revision = 'fbc835042266'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('VKEvent_auto',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('vk_event_type_id', sa.Integer(), nullable=False),
sa.Column('vk_event_args_json', sa.String(), nullable=False),
sa.PrimaryKeyConstraint('id')
)
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('VKEvent_auto')
# ### end Alembic commands ###

View File

@@ -0,0 +1,38 @@
"""Message update
Revision ID: 27bdc8eab961
Revises: cbb2ece35ae0
Create Date: 2018-10-20 02:46:05.272680
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '27bdc8eab961'
down_revision = 'cbb2ece35ae0'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('Message_auto', schema=None) as batch_op:
batch_op.add_column(sa.Column('attachments_json', sa.String(), nullable=False))
batch_op.add_column(sa.Column('extra_fields_json', sa.String(), nullable=False))
batch_op.add_column(sa.Column('text', sa.String(), nullable=False))
batch_op.drop_column('attachments')
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('Message_auto', schema=None) as batch_op:
batch_op.add_column(sa.Column('attachments', sa.VARCHAR(), nullable=False))
batch_op.drop_column('text')
batch_op.drop_column('extra_fields_json')
batch_op.drop_column('attachments_json')
# ### end Alembic commands ###

View File

@@ -0,0 +1,33 @@
"""Message more fields
Revision ID: 952c5d97aba3
Revises: 27bdc8eab961
Create Date: 2018-10-23 23:37:23.112830
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '952c5d97aba3'
down_revision = '27bdc8eab961'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('Message_auto', schema=None) as batch_op:
batch_op.add_column(sa.Column('is_bot_message', sa.Boolean(), nullable=False, default=False))
batch_op.add_column(sa.Column('is_outgoing', sa.Boolean(), nullable=False, default=False))
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('Message_auto', schema=None) as batch_op:
batch_op.drop_column('is_outgoing')
batch_op.drop_column('is_bot_message')
# ### end Alembic commands ###

View File

@@ -0,0 +1,34 @@
"""UserActivityPeriod
Revision ID: 20e307621653
Revises: 952c5d97aba3
Create Date: 2018-10-26 10:24:37.417570
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '20e307621653'
down_revision = '952c5d97aba3'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('UserActivityPeriod_auto',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('user_id', sa.Integer(), nullable=False),
sa.Column('period_start', sa.DateTime(), nullable=False),
sa.Column('period_end', sa.DateTime(), nullable=False),
sa.PrimaryKeyConstraint('id')
)
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('UserActivityPeriod_auto')
# ### end Alembic commands ###

View File

@@ -0,0 +1,41 @@
"""CachedDownload and CachedUpload
Revision ID: 253bd36e1037
Revises: 20e307621653
Create Date: 2018-10-27 02:06:35.782235
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '253bd36e1037'
down_revision = '20e307621653'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('CachedDownload_auto',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('url', sa.String(), nullable=False),
sa.Column('params_json', sa.String(), nullable=False),
sa.Column('local_path', sa.String(), nullable=False),
sa.PrimaryKeyConstraint('id')
)
op.create_table('CachedUpload_auto',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('local_path', sa.String(), nullable=False),
sa.Column('vk_object', sa.String(), nullable=False),
sa.PrimaryKeyConstraint('id')
)
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('CachedUpload_auto')
op.drop_table('CachedDownload_auto')
# ### end Alembic commands ###

View File

@@ -0,0 +1,32 @@
"""add peer_id to Message
Revision ID: 3283fcaa655e
Revises: 253bd36e1037
Create Date: 2018-11-09 20:29:11.432988
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '3283fcaa655e'
down_revision = '253bd36e1037'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('Message_auto', schema=None) as batch_op:
batch_op.add_column(sa.Column('peer_id', sa.Integer(), nullable=False, server_default='0'))
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('Message_auto', schema=None) as batch_op:
batch_op.drop_column('peer_id')
# ### end Alembic commands ###

View File

@@ -0,0 +1,32 @@
"""add TimetableJson
Revision ID: 70e4787571c6
Revises: 3283fcaa655e
Create Date: 2019-03-02 18:49:05.324919
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '70e4787571c6'
down_revision = '3283fcaa655e'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('TimetableJson_auto',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('json', sa.String(), nullable=True),
sa.PrimaryKeyConstraint('id')
)
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('TimetableJson_auto')
# ### end Alembic commands ###