Junior — Middle
Have you created your own migration scripts or tools for database management?
sobes.tech AI
Answer from AI
Yes, I have created custom migration scripts to manage the database schema. Usually, these are a set of SQL files or Python scripts that are applied sequentially to update the database structure without data loss. For example, you can write a simple script that checks the current schema version and applies the necessary changes:
import sqlite3
conn = sqlite3.connect('example.db')
c = conn.cursor()
# Get the current schema version
c.execute("PRAGMA user_version")
version = c.fetchone()[0]
if version < 1:
c.execute('ALTER TABLE users ADD COLUMN age INTEGER')
c.execute('PRAGMA user_version = 1')
conn.commit()
conn.close()
This approach allows manual control of migrations if you cannot use ready-made tools like Alembic or Flyway.