This is an in-development version. Grow with us! 🎉

Migrations

Introduction

Migrations are a crucial component for defining and managing database changes in the Fustak framework. They are implemented through *.db** files located in the **src/migrations folder. Each migration file represents a specific set of modifications to be applied to the database.

Migration File Structure

A migration is defined within a *.db file, where the file name itself serves as a means of tracking the order of migrations. However, the file name does not have any other functional significance. To ensure consistency and clarity, the following recommendations should be followed when naming migration files:

  • − The migration file should be formatted as <​VERSION><​DESCRIPTION><​TYPE>.db.
  • − The <​VERSION> should be in the format of YYYYMMDD to represent the date of the migration.
  • − The <​DESCRIPTION> should provide a brief description of the migration's purpose.
  • − The <​TYPE> should be either "up" or "down" to indicate whether the migration applies changes (up) or reverts them (down).

Applying and Reverting Migrations

Migrations with the type "up" are used to apply the defined changes to the database, while migrations with the type "down" are used to revert those changes.

For example, if you need to create a migration for a "users" table, you can create a file named 20210101_create_users_table_up.db to define the migration for creating the table. Additionally, you would create a file named 20210101_create_users_table_down.db to define the migration for reverting the creation of the table.

Deploying Migrations

To deploy a migration to the server, use the command fustak migrations [PATH], where [PATH] represents the location of the migration file.

It is essential to run the appropriate migration command to ensure that the defined changes are correctly applied or reverted within the database.

Please note that migrations play a vital role in maintaining a consistent and updated database schema, and careful attention should be given to their execution and sequencing.