fix: Correct latest migration alembic/versions/20250414_024110_fd7a3654_update_fruit.py via AI
This commit is contained in:
parent
953a41a660
commit
bff627b060
@ -17,11 +17,23 @@ def upgrade():
|
|||||||
sa.Column('id', sa.String(36), primary_key=True),
|
sa.Column('id', sa.String(36), primary_key=True),
|
||||||
sa.Column('name', sa.String(), nullable=False),
|
sa.Column('name', sa.String(), nullable=False),
|
||||||
sa.Column('color', sa.String(), nullable=False),
|
sa.Column('color', sa.String(), nullable=False),
|
||||||
sa.Column('created_at', sa.DateTime(), server_default=sa.func.now()),
|
sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP')),
|
||||||
sa.Column('updated_at', sa.DateTime(), server_default=sa.func.now())
|
sa.Column('updated_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP'))
|
||||||
)
|
)
|
||||||
op.create_index(op.f('ix_fruits_name'), 'fruits', ['name'], unique=False)
|
op.create_index(op.f('ix_fruits_name'), 'fruits', ['name'], unique=False)
|
||||||
|
|
||||||
|
# Create trigger for updated_at
|
||||||
|
op.execute('''
|
||||||
|
CREATE TRIGGER trig_fruits_updated_at
|
||||||
|
AFTER UPDATE ON fruits
|
||||||
|
FOR EACH ROW
|
||||||
|
BEGIN
|
||||||
|
UPDATE fruits SET updated_at = CURRENT_TIMESTAMP
|
||||||
|
WHERE id = NEW.id;
|
||||||
|
END;
|
||||||
|
''')
|
||||||
|
|
||||||
def downgrade():
|
def downgrade():
|
||||||
|
op.execute('DROP TRIGGER IF EXISTS trig_fruits_updated_at')
|
||||||
op.drop_index(op.f('ix_fruits_name'), table_name='fruits')
|
op.drop_index(op.f('ix_fruits_name'), table_name='fruits')
|
||||||
op.drop_table('fruits')
|
op.drop_table('fruits')
|
Loading…
x
Reference in New Issue
Block a user