Fw Database
These are the API Docs for the fw database command added by Migration Core. The main purpose for this command is to control the database migrations written to change the database. The more comprehensive guide which describes how to write a database migration can be found above, Writing Migrations. Below you will find a base description of how the fw database command works.
Directory to Run
This command can only be run in the base folder of an app (ie fw-dev/apps/sta) which has Migration Core installed as an FW Addon (which currently is all of our apps).
Arguments
There are two arguments which can be used with this command:
actionis a required argument, which is limited to only three options, each doing a specific thing:createwill create a new empty migration file at the directoryserver/data/migrations, formatted with the current time stamp followed by the next database migration number. (ie the migration number ten created on 9/17/24 would be titled:20240917095438_ten.php).migratewill run theupfunctions on all migrations that have not been logged as completed in the{appId}_migration_logon the database, until the newest migration (or the migration version specified by the version argument). It will also amend themigration_logtable accordingly.rollbackwill run thedownfunction on the most recent migration completed (ie if the most recently run migration was 10, it will run thedownfunction on 10, and then be on Database version 9). Ifversionis specified it will run all of thedownfunctions until the database is on the version specified (sofw database rollback 5will run down functions on 10 through 6, leaving the database on 5). It will also amend the migration log accordingly.
versionis the migration version to go to. It is used to change the default behavior for eithermigrateorrollbackcommands, as described in those action options. It is helpful to remember that after runningrollbackormigratewith a version specified, the database will be on that version (which explains whymigratewill run theupfunction of the specified version, androllbackwill only run thedownfunctions up to that version). This argument won't do anything with acreateaction.
Extra Options
There are no additional options for the fw database command beyond those available for all fw installer commands.
Usage
So here is the structure of the fw database command. If it is wrapped in <> it is a required, wrapped in [] means it is optional.
C:\Users\[user]\fw-dev\apps\sta> fw database <action> [version]