add migration

This commit is contained in:
Vyacheslav Anzhiganov 2017-10-20 05:19:07 +03:00
parent d39ab585a9
commit 3aa9ce6065
5 changed files with 63 additions and 1 deletions

View file

@ -0,0 +1,43 @@
"""empty message
Revision ID: 92040f86c12b
Revises: e75eb58a894e
Create Date: 2017-10-20 03:55:16.731533
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
# revision identifiers, used by Alembic.
revision = '92040f86c12b'
down_revision = 'e75eb58a894e'
branch_labels = None
depends_on = None
def upgrade():
op.create_table(
'rush',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('at_start', sa.DateTime(), nullable=False),
sa.Column('at_finish', sa.DateTime(), nullable=False),
sa.Column('bet', sa.Integer(), nullable=False),
sa.Column('status', sa.String(length=32), nullable=False),
sa.PrimaryKeyConstraint('id')
)
op.create_table(
'rush_accounts',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('rush_id', sa.Integer(), nullable=False),
sa.Column('account_id', sa.Integer(), nullable=False),
sa.ForeignKeyConstraint(['account_id'], ['wot_accounts.account_id'], ),
sa.ForeignKeyConstraint(['rush_id'], ['rush.id'], ),
sa.PrimaryKeyConstraint('id')
)
def downgrade():
op.drop_table('rush_accounts')
op.drop_table('rush')

View file

@ -1,6 +1,7 @@
flask
flask_sqlalchemy
Flask-Migrate
Flask-Script
validators
jsonschema
Flask-JWT

View file

@ -8,3 +8,4 @@ from .userwotdata import UserWotData
from .wotaccounts import WotAccounts
from .wotaccountsstats import WotAccountsStats
from .rush import Rush
from .rushaccounts import RushAccounts

View file

@ -0,0 +1,17 @@
from wotstats.database import db
class RushAccounts(db.Model):
id = db.Column(db.Integer, primary_key=True)
rush_id = db.Column(db.Integer, db.ForeignKey('rush.id'), nullable=False)
account_id = db.Column(db.Integer, db.ForeignKey('wot_accounts.account_id'), nullable=False)
def __init__(self, account_id, nickname):
self.account_id = account_id
self.rush_id = rush_id
def __repr__(self):
return '<RushAccounts rush_id={} account_id={}>'.format(
self.rush_id, self.account_id
)

View file

@ -10,7 +10,7 @@ from wotstats.database import db
from wotstats.models import Rush
# from wotstats.lib import parse_wargaming_openid_url
pages_wallet = Blueprint(
pages_rush = Blueprint(
'pages_rush', __name__,
url_prefix='/rush',
template_folder='templates')