Migrate data from one environment to another

I am trying to find the best way to update one environment with the data from another. I tested the new migration command ‘8base migration commit’ but it seems to work only for migrations that have been generated in the same environment.

Any idea?
Thanks

We’re working on improving the docs for CI/CD. Hold tight!

We are about to launch a big release this coming week.
Can you give us a quick explanation of what to do?

R

I’ve sent this thread to our engineering team asking them to comment!

Hi!

We are working on ci/cd documentation and will release it soon.

8base migration is a file with the code that would be executed during performing commit command.
They are placed in the directory migrations in your project. Each migration has to export a string with the name ‘version’ and function with the name ‘up’.
For now, the version equals ‘v1’. In function ‘up’ you describe the migration’s code. You can use generated migration as an template.

There are several migration commands

  1. ‘8base migration status’. The command shows the difference between local migrations in directory <project_path>/migrations and already enrolled migrations. Before each commit command, we recommend performing this command to see which migrations would be committed.
  2. ‘8base migration generate’. The command generates migrations on changes which have been applied to schema or system data before.
    There are two types of data: system and custom. System data is a schema, auth profiles, roles, permissions. Custom data is data from user’s tables.
  3. ‘8base migration commit’. Command commits new migrations to the current environment.
  4. ‘8base environment branch -n -m FULL/SYSTEM’. If you need to clone the environment with only system data you need to choose ‘SYSTEM’. If you need to clone the whole environment choose “FULL” mode.
  5. ‘8base environment set’. Command switch environment.
  6. ‘8base environment show’. Command show current environment.
  7. ‘8base backup craete’. Command create the whole backup of current envionment.
  8. ‘8base backup list’. Command show the available backups for current environment.
  9. ‘8base backup restore --backup=<backup_name>’. This command returns the current environment to the state when its backup was created.

How to use migration commands for system data.

  1. We have the environment with the name ‘dev’ which was inherited from branch ‘staging’.
  2. Create table ‘test’ from client web.
  3. Perform ‘8base migration generate’. There is new migration in the folder /migrations with code to create a table with the name ‘test’.
  4. Perform ‘8base environment set -n staging’ to switch current environment to ‘staging’.
  5. Perform ‘8base migration status’. It should show the new migration which will be deployed to the ‘staging’ branch.
  6. Perform ‘8base migration commit’ to commit new migrations to the current environment.

Also, you can generate migrations for custom data.

  1. We have the environment with the name ‘dev’ which was inherited from branch ‘staging’.
  2. There is a user table with the name “TestTable” with relation field to “TestTable2”.
  3. Perform ‘8base migration generate --tables=TestTable TestTable2’
  4. There are new migrations for specified tables with code to create data. If tables have relations command will generate update migration to bind the table’s data.
  5. Switch environment.
  6. Perform ‘8base migration status’. Check new migrations to commit.
  7. Perform ‘8base migration commit’ to commit custom data to another environment.

Be careful. Migrations generate data with record id. If you have cloned environment with FULL mode target environment may to have values with the same id. To avoid this problem you have to destroy the record on the target branch.
If you just delete the record it still will not be able to commit new migrations because of duplicate id.

Alse we recommend to create backup any time before you perform the ‘commit’ command to have opporunity to rollback the environment’s state.

As I understand, you want to clone custom data between environments. Try to follow the actions described above.

Feel free to ask any questions!

1 Like