From f407aeeca5d4e30bdebed7cf41c26f26f46cd2a9 Mon Sep 17 00:00:00 2001 From: Luca Haid Date: Wed, 7 Feb 2024 15:47:45 +0100 Subject: [PATCH] Add TheTool database migration documentation --- db/README.md | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 db/README.md diff --git a/db/README.md b/db/README.md new file mode 100644 index 000000000..031bfd45c --- /dev/null +++ b/db/README.md @@ -0,0 +1,54 @@ +# TheTool Database Migrations +## Introduction + +This project utilizes Phinx for Database Migrations + +## Table of Contents +- [Initializing Phinx](#Initializing) +- [Creating Migrations](#creating-migrations) +- [Migrating / Rolling Back](#migrating--rolling-back) +- [Documentation](#documentation) + +## Initializing + +To start using Phinx for database migrations, you first need to initialize Phinx and set up your configuration. Run the following command in your project directory: + +```bash +vendor/bin/phinx init +``` + +After initialization, add two environments: `thetool` and `thetool_addressdb` to your Phinx configuration to ensure it functions correctly with TheTool's database setup. + +## Usage +### Creating Migrations + +To create a new database migration, use the command below + +Custom Template -t : `db/template/migrate.up_down.template` +Replace `{MIGRATION_NAME}` : Example `AddNewTable` + +```bash +vendor/bin/phinx create {MIGRATION_NAME} -t db/template/migrate.up_down.template +``` + +A new migration file will be created in `db/migrations` + +### Migrating / Rolling Back + +Use the following command to apply the migrations. + +Use `-t={TARGET_TIMESTAMP}` to go to a specific migration target +Use `--dry-run` to simulate the Migratio + +```bash +vendor/bin/phinx migrate [-t={TARGET_TIMESTAMP}] [--dry-run] +``` + +Use the following command to undo the migrations. + +```bash +vendor/bin/phinx rollback [-t={TARGET_TIMESTAMP}] [--dry-run] +``` +## Documentation + +For more detailed information on using Phinx, visit the [Phinx documentation](https://book.cakephp.org/phinx/0/en/intro.html) . \ No newline at end of file