Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: migrate from environment_namespace to environment_id #884

Closed
cre8ivejp opened this issue Mar 22, 2024 · 0 comments · Fixed by #1457
Closed

chore: migrate from environment_namespace to environment_id #884

cre8ivejp opened this issue Mar 22, 2024 · 0 comments · Fixed by #1457
Assignees
Labels

Comments

@cre8ivejp
Copy link
Member

cre8ivejp commented Mar 22, 2024

As part of the Organization feature, we must migrate to environment_id soon to avoid future bugs and conflicts.

We will replace the environment_namespace column with the environment_id column for all tables; this PR will first add the environment_id column.

Here is the migration process:

  1. Add a new column
    Add the environment_id column to all relevant tables, allowing NULL initially

    ALTER TABLE `table_name` ADD COLUMN `environment_id` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NULL;
  2. Populate a new column
    Populate the new environment_id column with data from environment_namespace:

    UPDATE `table_name` SET `environment_id` = `environment_namespace`;
  3. Update backend service (Phase 1)
    Update service to write to both environment_namespace and environment_id columns. Read primarily from environment_id, falling back to environment_namespace if environment_id is NULL. This ensures compatibility with both old and new data.

  4. Backfill any missing data
    If any data was written during the deployment of the updated service:

    UPDATE `table_name` SET `environment_id` = `environment_namespace` WHERE `environment_id` IS NULL;
  5. Make new column NOT NULL
    After verifying all data is populated:

    ALTER TABLE `table_name` MODIFY COLUMN `environment_id` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL;
  6. Update backend service (Phase 2)
    Update service to only write to and read from environment_id. Remove all references to environment_namespace.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Done 2025
Development

Successfully merging a pull request may close this issue.

2 participants