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:
action
is a required argument, which is limited to only three options, each doing a specific thing:create
will 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
).migrate
will run theup
functions on all migrations that have not been logged as completed in the{appId}_migration_log
on the database, until the newest migration (or the migration version specified by the version argument). It will also amend themigration_log
table accordingly.rollback
will run thedown
function on the most recent migration completed (ie if the most recently run migration was 10, it will run thedown
function on 10, and then be on Database version 9). Ifversion
is specified it will run all of thedown
functions until the database is on the version specified (sofw database rollback 5
will run down functions on 10 through 6, leaving the database on 5). It will also amend the migration log accordingly.
version
is the migration version to go to. It is used to change the default behavior for eithermigrate
orrollback
commands, as described in those action options. It is helpful to remember that after runningrollback
ormigrate
with a version specified, the database will be on that version (which explains whymigrate
will run theup
function of the specified version, androllback
will only run thedown
functions up to that version). This argument won't do anything with acreate
action.
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]