"""init databases Revision ID: 1b3bc6809b30 Revises: Create Date: 2024-08-15 15:09:26.124279 """ from alembic import op import sqlalchemy as sa # revision identifiers, used by Alembic. revision = '1b3bc6809b30' down_revision = None branch_labels = None depends_on = None def upgrade(): # ### commands auto generated by Alembic - please adjust! ### op.create_table('log', sa.Column('id', sa.Integer(), nullable=False), sa.Column('log_user_agent', sa.String(length=120), nullable=True), sa.Column('log_method', sa.String(length=120), nullable=True), sa.Column('log_quest_path', sa.String(length=120), nullable=True), sa.Column('log_ip', sa.String(length=120), nullable=True), sa.Column('log_params', sa.String(length=120), nullable=True), sa.Column('log_controller', sa.String(length=120), nullable=True), sa.Column('log_controller_action', sa.String(length=120), nullable=True), sa.Column('log_controller_id', sa.String(length=120), nullable=True), sa.Column('account_id', sa.String(length=120), nullable=True), sa.Column('event_name', sa.String(length=120), nullable=True), sa.Column('event_content', sa.Text(), nullable=True), sa.Column('operator', sa.String(length=120), nullable=True), sa.Column('created_at', sa.DateTime(), nullable=True), sa.Column('updated_at', sa.DateTime(), nullable=True), sa.PrimaryKeyConstraint('id') ) op.create_table('passenger', sa.Column('id', sa.Integer(), nullable=False), sa.Column('name', sa.String(length=120), nullable=True), sa.Column('account', sa.String(length=120), nullable=False), sa.Column('password_digest', sa.String(length=2000), nullable=False), sa.Column('id_card_no', sa.String(length=120), nullable=True), sa.Column('mobile_no', sa.String(length=120), nullable=True), sa.Column('bank_card_no', sa.String(length=120), nullable=True), sa.Column('state', sa.Integer(), nullable=True), sa.Column('member_type', sa.Integer(), nullable=True), sa.Column('last_login_time', sa.DateTime(), nullable=True), sa.Column('created_at', sa.DateTime(), nullable=True), sa.Column('updated_at', sa.DateTime(), nullable=True), sa.PrimaryKeyConstraint('id') ) with op.batch_alter_table('passenger', schema=None) as batch_op: batch_op.create_index(batch_op.f('ix_passenger_account'), ['account'], unique=True) op.create_table('station', sa.Column('id', sa.Integer(), nullable=False), sa.Column('name', sa.String(length=120), nullable=False), sa.Column('pinyin', sa.String(length=120), nullable=True), sa.Column('province', sa.String(length=120), nullable=True), sa.Column('city', sa.String(length=120), nullable=True), sa.Column('district', sa.String(length=120), nullable=True), sa.Column('created_at', sa.DateTime(), nullable=True), sa.Column('updated_at', sa.DateTime(), nullable=True), sa.PrimaryKeyConstraint('id') ) with op.batch_alter_table('station', schema=None) as batch_op: batch_op.create_index(batch_op.f('ix_station_name'), ['name'], unique=True) op.create_table('train', sa.Column('id', sa.Integer(), nullable=False), sa.Column('train_no', sa.String(length=120), nullable=False), sa.Column('departure_station', sa.String(length=120), nullable=True), sa.Column('arrival_station', sa.String(length=120), nullable=True), sa.Column('departure_time', sa.DateTime(), nullable=True), sa.Column('expiration_time', sa.DateTime(), nullable=True), sa.Column('effective_time', sa.DateTime(), nullable=True), sa.Column('arrival_time', sa.DateTime(), nullable=True), sa.Column('created_at', sa.DateTime(), nullable=True), sa.Column('updated_at', sa.DateTime(), nullable=True), sa.PrimaryKeyConstraint('id') ) with op.batch_alter_table('train', schema=None) as batch_op: batch_op.create_index(batch_op.f('ix_train_train_no'), ['train_no'], unique=True) op.create_table('order', sa.Column('id', sa.Integer(), nullable=False), sa.Column('order_no', sa.String(length=120), nullable=False), sa.Column('price', sa.Numeric(precision=8, scale=2), nullable=True), sa.Column('payment_time', sa.DateTime(), nullable=True), sa.Column('state', sa.Integer(), nullable=True), sa.Column('passenger_id', sa.Integer(), nullable=False), sa.Column('created_at', sa.DateTime(), nullable=True), sa.Column('updated_at', sa.DateTime(), nullable=True), sa.ForeignKeyConstraint(['passenger_id'], ['passenger.id'], ), sa.PrimaryKeyConstraint('id'), sa.UniqueConstraint('order_no') ) with op.batch_alter_table('order', schema=None) as batch_op: batch_op.create_index(batch_op.f('ix_order_passenger_id'), ['passenger_id'], unique=False) op.create_table('train_station', sa.Column('id', sa.Integer(), nullable=False), sa.Column('train_no', sa.String(length=120), nullable=False), sa.Column('station_name', sa.String(length=120), nullable=False), sa.Column('price', sa.Numeric(precision=8, scale=2), nullable=True), sa.Column('arrival_time', sa.DateTime(), nullable=True), sa.Column('departure_time', sa.DateTime(), nullable=True), sa.Column('index', sa.Integer(), nullable=True), sa.Column('created_at', sa.DateTime(), nullable=True), sa.Column('updated_at', sa.DateTime(), nullable=True), sa.ForeignKeyConstraint(['station_name'], ['station.name'], ), sa.ForeignKeyConstraint(['train_no'], ['train.train_no'], ), sa.PrimaryKeyConstraint('id', 'train_no', 'station_name') ) with op.batch_alter_table('train_station', schema=None) as batch_op: batch_op.create_index(batch_op.f('ix_train_station_train_no'), ['train_no'], unique=False) op.create_table('ticket', sa.Column('id', sa.Integer(), nullable=False), sa.Column('seat_no', sa.String(length=120), nullable=True), sa.Column('seat_class', sa.String(length=120), nullable=True), sa.Column('price', sa.Numeric(precision=8, scale=2), nullable=True), sa.Column('state', sa.Integer(), nullable=True), sa.Column('train_no', sa.String(length=120), nullable=False), sa.Column('passenger_id', sa.Integer(), nullable=False), sa.Column('order_id', sa.Integer(), nullable=False), sa.Column('from_station', sa.String(length=120), nullable=True), sa.Column('to_station', sa.String(length=120), nullable=True), sa.Column('date', sa.String(length=120), nullable=True), sa.Column('departure_time', sa.DateTime(), nullable=True), sa.Column('arrival_time', sa.DateTime(), nullable=True), sa.Column('created_at', sa.DateTime(), nullable=True), sa.Column('updated_at', sa.DateTime(), nullable=True), sa.ForeignKeyConstraint(['order_id'], ['order.id'], ), sa.ForeignKeyConstraint(['passenger_id'], ['passenger.id'], ), sa.ForeignKeyConstraint(['train_no'], ['train.train_no'], ), sa.PrimaryKeyConstraint('id') ) with op.batch_alter_table('ticket', schema=None) as batch_op: batch_op.create_index(batch_op.f('ix_ticket_order_id'), ['order_id'], unique=False) batch_op.create_index(batch_op.f('ix_ticket_passenger_id'), ['passenger_id'], unique=False) batch_op.create_index(batch_op.f('ix_ticket_train_no'), ['train_no'], unique=False) # ### end Alembic commands ### def downgrade(): # ### commands auto generated by Alembic - please adjust! ### with op.batch_alter_table('ticket', schema=None) as batch_op: batch_op.drop_index(batch_op.f('ix_ticket_train_no')) batch_op.drop_index(batch_op.f('ix_ticket_passenger_id')) batch_op.drop_index(batch_op.f('ix_ticket_order_id')) op.drop_table('ticket') with op.batch_alter_table('train_station', schema=None) as batch_op: batch_op.drop_index(batch_op.f('ix_train_station_train_no')) op.drop_table('train_station') with op.batch_alter_table('order', schema=None) as batch_op: batch_op.drop_index(batch_op.f('ix_order_passenger_id')) op.drop_table('order') with op.batch_alter_table('train', schema=None) as batch_op: batch_op.drop_index(batch_op.f('ix_train_train_no')) op.drop_table('train') with op.batch_alter_table('station', schema=None) as batch_op: batch_op.drop_index(batch_op.f('ix_station_name')) op.drop_table('station') with op.batch_alter_table('passenger', schema=None) as batch_op: batch_op.drop_index(batch_op.f('ix_passenger_account')) op.drop_table('passenger') op.drop_table('log') # ### end Alembic commands ###