# sqlite3def ``` Usage: sqlite3def [OPTIONS] [FILENAME|current.sql] < desired.sql Application Options: -f, --file=FILENAME Read desired SQL from the file, rather than stdin (default: -) --dry-run Don't run DDLs but just show them --export Just dump the current schema to stdout --enable-drop Enable destructive changes such as DROP for TABLE, SCHEMA, ROLE, USER, FUNCTION, PROCEDURE, TRIGGER, VIEW, INDEX, SEQUENCE, TYPE --config=PATH YAML configuration file (can be specified multiple times) --config-inline=YAML YAML configuration as inline string (can be specified multiple times) --help Show this help --version Show version information ``` ## Synopsis ```shell # Create SQLite database and tables $ sqlite3 mydb.db "CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT);" # Export current schema $ sqlite3def mydb.db --export CREATE TABLE users ( id INTEGER PRIMARY KEY, name TEXT ); # Save it to edit $ sqlite3def mydb.db --export > schema.sql ``` Update schema.sql as follows: ```diff CREATE TABLE users ( id INTEGER PRIMARY KEY, - name TEXT + name TEXT, + email TEXT NOT NULL ); + +CREATE INDEX idx_users_email ON users(email); ``` And then run: ```shell # Preview migration plan (dry run) $ sqlite3def mydb.db --dry-run < schema.sql -- dry run -- BEGIN; ALTER TABLE users ADD COLUMN email TEXT NOT NULL; CREATE INDEX idx_users_email ON users(email); COMMIT; # Apply DDLs $ sqlite3def mydb.db < schema.sql -- Apply -- BEGIN; ALTER TABLE users ADD COLUMN email TEXT NOT NULL; CREATE INDEX idx_users_email ON users(email); COMMIT; # Operations are idempotent - safe to run multiple times $ sqlite3def mydb.db < schema.sql -- Nothing is modified -- # Run without dropping tables and columns $ sqlite3def mydb.db < schema.sql -- Skipped: DROP TABLE old_users; # Run with drop operations enabled $ sqlite3def mydb.db --enable-drop < schema.sql -- Apply -- BEGIN; DROP TABLE old_users; COMMIT; # Use config file to filter tables $ cat > config.yml <