Package: cozo-migrate
cozo-migrateA simple utility for migrations for cozo dbFeaturesIt usestyperandpycozoas its only dependencies.Loosely modeled afterhasura-migratewhich is one of the simplest migration tools I have used.Auto-rollback if something goes wrong during the migrationsHas a programmatic API for using inside tests etc.CLI UsageExample$# Install cozo-migrate$pipinstallcozo-migrate

$# Let's start a cozo server in the background$cozoserver-erocksdb&$# Let's create a migration$cozo-migrate-ehttp-d./migrationscreatedemoWriting'migrations/migrate_1704803704_demo.py'Confirm?[y/N]:y✔Createdmigrationat:migrations/migrate_1704803704_demo.py

$catmigrations/migrate_1704803704_demo.py#/usr/bin/env python3MIGRATION_ID="demo"CREATED_AT=1704803704.762879defup(client):passdefdown(client):pass

$# Edit the migration to add schema change queries and then apply!$cozo-migrate-ehttp-d./migrationsapply-a•Migratepath:[NONE]→demoAreyousureyouwanttoapplythesemigrations?[y/N]:y✔Databasemigrated.Core optionsUsage:cozo-migrate[OPTIONS]COMMAND[ARGS]...AsimplemigrationtoolforCozodatabases.

╭─Options──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│--migrations-dir-dPATHDirectorytouseforlookingupmigrationfiles.[envvar:COZO_MIGRATIONS_DIR][default:migrations]│
│--engine-e[sqlite|rocksdb|http|mem]Enginetouse[envvar:COZO_ENGINE][default:EngineType.sqlite]│
│--path-fPATHDatabasefile(notapplicableformemorhttpengines)[envvar:COZO_PATH][default:None]│
│--host-hTEXTHosttoconnectto(httpengineonly)[envvar:COZO_HOST][default:http://127.0.0.1:9070]│
│--authTEXTAuthheader(httpengineonly)[default:None]│
│--verbose-v│
│--install-completionInstallcompletionforthecurrentshell.│
│--show-completionShowcompletionforthecurrentshell,tocopyitorcustomizetheinstallation.│
│--helpShowthismessageandexit.│
╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
╭─Commands────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│applyApplymigrationstothedatabase.Youcanspecifythenumberofstepstoapplyandthedirection.│
│createCreateanewmigrationfileinthemigrationsdirectory.Format:{migration_dir}/migrate_<timestamp>_<id>.py│
│historyDisplaythemigrationhistoryinthedatabaseasaprettytable.│
│initInitializethedatabasewiththemigrationmanagertable.│
│statusDisplaythecurrentmigrationstatus.│
│versionDisplaythecurrentversion.│
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯InitUsage:cozo-migrateinit[OPTIONS]Initializethedatabasewiththemigrationmanagertable.

╭─Options───────────────────────────────────╮
│--helpShowthismessageandexit.│
╰─────────────────────────────────────────────╯CreateUsage:cozo-migratecreate[OPTIONS]IDCreateanewmigrationfileinthemigrationsdirectory.Format:{migration_dir}/migrate_<timestamp>_<id>.py

╭─Arguments───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│*idTEXTAshort,descriptive,alphanumericidforthemigration.Onlyletters,numbers,andunderscoresareallowed.[required]│
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
╭─Options─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│--yes-y│
│--helpShowthismessageandexit.│
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ApplyUsage:cozo-migrateapply[OPTIONS][STEPS]Applymigrationstothedatabase.Youcanspecifythenumberofstepstoapplyandthedirection.

╭─Arguments────────────────────────╮
│steps[STEPS][default:1]│
╰────────────────────────────────────╯
╭─Options──────────────────────────────────────╮
│--down│
│--all-a│
│--yes-y│
│--helpShowthismessageandexit.│
╰────────────────────────────────────────────────╯StatusUsage:cozo-migratestatus[OPTIONS]Displaythecurrentmigrationstatus.

╭─Options────────────────────────────────────╮
│--helpShowthismessageandexit.│
╰──────────────────────────────────────────────╯HistoryUsage:cozo-migratehistory[OPTIONS]Displaythemigrationhistoryinthedatabaseasaprettytable.

╭─Options────────────────────────────────────╮
│--helpShowthismessageandexit.│
╰──────────────────────────────────────────────╯API Usagefromcozo_migrate.apiimportinit,applyfrompycozoimportClientmigrations_dir:str="./migrations"# Create a new client for testing# and initialize the schema.client=Client()# Initialize the migration schemainit(client)# Apply migrations from the migration directoryapply(client,migrations_dir=migrations_dir,all_=True)