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 directory server/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 the up 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 the migration_log table accordingly.
    • rollback will run the down function on the most recent migration completed (ie if the most recently run migration was 10, it will run the down function on 10, and then be on Database version 9). If version is specified it will run all of the down functions until the database is on the version specified (so fw 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 either migrate or rollback commands, as described in those action options. It is helpful to remember that after running rollback or migrate with a version specified, the database will be on that version (which explains why migrate will run the up function of the specified version, and rollback will only run the down functions up to that version). This argument won't do anything with a create 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]