fleet/docs/4-Contribution/3-Migrations.md
noahtalerman 9fb9da31f5
Bring Orbit docs into Fleet docs and add FAQ section (#717)
- Add new `2-Orbit-osquery/` directory to the top-level `docs/` directory.
- Rename `2-Deployment/` -> `3-Deployment/` to accommodate new Orbit directory.
- Rename `3-Contribution/` ->  `4-Contribution/` to accommodate new Orbit directory.
- Add FAQ section to Orbit documentation.
2021-05-04 15:50:18 -04:00

2 KiB

Fleet Database migrations

Adding/Updating tables

Database schemas are managed by a series of migrations defined in go code. We use a customized version of the Goose migrations tool to handle these migrations.

Note: Once committed to the Fleet repo, table migrations should be considered immutable. Any changes to an existing table should take place in a new migration executing ALTERs.

From the project root run the following shell command:

make migration name=NameOfMigration

Now edit the generated migration file in server/datastore/mysql/migrations/tables/.

You can then update the database by running the following shell commands:

make fleet
./build/fleet prepare db

Populating the database with default data

Note: This pattern will soon be changing. Please check with @zwass if you think you need to write a data migration.

Populating built in data is also performed through migrations. All table migrations are performed before any data migrations.

Note: Data migrations can be mutable. If tables are altered in a way that would render a data migration invalid (columns changed/removed), data migrations should be updated to comply with the new schema. Data migrations will not be re-run when they have already been run against a database, but they must be updated to maintain compatibility with a fresh DB.

From the project root run the following shell command:

make migration name=NameOfMigration

Move the migration file from server/datastore/mysql/migrations/tables/ to server/datastore/mysql/migrations/data/, and change the package tables to package data.

Proceed as for table migrations, editing and running the newly created migration file.