From 6365db42f950b62fe4ab133f2b527ec4010b2983 Mon Sep 17 00:00:00 2001 From: Sattvik Chakravarthy Date: Thu, 14 Mar 2024 15:17:11 +0530 Subject: [PATCH] fix: migration scripts --- CHANGELOG.md | 132 ++++++++++++++++++++++++++------------------------- 1 file changed, 67 insertions(+), 65 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c9946f0d8..37f1f12b7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -42,79 +42,81 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ### Migration -
- - If using PostgreSQL - - ```sql - CREATE TABLE IF NOT EXISTS tenant_first_factors ( - connection_uri_domain VARCHAR(256) DEFAULT '', - app_id VARCHAR(64) DEFAULT 'public', - tenant_id VARCHAR(64) DEFAULT 'public', - factor_id VARCHAR(128), - CONSTRAINT tenant_first_factors_pkey - PRIMARY KEY (connection_uri_domain, app_id, tenant_id, factor_id), - CONSTRAINT tenant_first_factors_tenant_id_fkey - FOREIGN KEY (connection_uri_domain, app_id, tenant_id) - REFERENCES tenant_configs (connection_uri_domain, app_id, tenant_id) ON DELETE CASCADE - ); +Make sure the core is already upgraded to version 8.0.0 before migrating - CREATE INDEX IF NOT EXISTS tenant_first_factors_tenant_id_index ON - tenant_first_factors (connection_uri_domain, app_id, tenant_id); +
- CREATE TABLE IF NOT EXISTS tenant_required_secondary_factors ( - connection_uri_domain VARCHAR(256) DEFAULT '', - app_id VARCHAR(64) DEFAULT 'public', - tenant_id VARCHAR(64) DEFAULT 'public', - factor_id VARCHAR(128), - CONSTRAINT tenant_required_secondary_factors_pkey - PRIMARY KEY (connection_uri_domain, app_id, tenant_id, factor_id), - CONSTRAINT tenant_required_secondary_factors_tenant_id_fkey - FOREIGN KEY (connection_uri_domain, app_id, tenant_id) - REFERENCES tenant_configs (connection_uri_domain, app_id, tenant_id) ON DELETE CASCADE - ); - - CREATE INDEX IF NOT EXISTS tenant_default_required_factor_ids_tenant_id_index ON - tenant_required_secondary_factors (connection_uri_domain, app_id, tenant_id); - - ALTER TABLE totp_user_devices ADD COLUMN IF NOT EXISTS created_at BIGINT default 0; - ALTER TABLE totp_user_devices - ALTER COLUMN created_at DROP DEFAULT; - ``` - -
+If using PostgreSQL -
+```sql +CREATE TABLE IF NOT EXISTS tenant_first_factors ( + connection_uri_domain VARCHAR(256) DEFAULT '', + app_id VARCHAR(64) DEFAULT 'public', + tenant_id VARCHAR(64) DEFAULT 'public', + factor_id VARCHAR(128), + CONSTRAINT tenant_first_factors_pkey + PRIMARY KEY (connection_uri_domain, app_id, tenant_id, factor_id), + CONSTRAINT tenant_first_factors_tenant_id_fkey + FOREIGN KEY (connection_uri_domain, app_id, tenant_id) + REFERENCES tenant_configs (connection_uri_domain, app_id, tenant_id) ON DELETE CASCADE +); + +CREATE INDEX IF NOT EXISTS tenant_first_factors_tenant_id_index ON + tenant_first_factors (connection_uri_domain, app_id, tenant_id); + +CREATE TABLE IF NOT EXISTS tenant_required_secondary_factors ( + connection_uri_domain VARCHAR(256) DEFAULT '', + app_id VARCHAR(64) DEFAULT 'public', + tenant_id VARCHAR(64) DEFAULT 'public', + factor_id VARCHAR(128), + CONSTRAINT tenant_required_secondary_factors_pkey + PRIMARY KEY (connection_uri_domain, app_id, tenant_id, factor_id), + CONSTRAINT tenant_required_secondary_factors_tenant_id_fkey + FOREIGN KEY (connection_uri_domain, app_id, tenant_id) + REFERENCES tenant_configs (connection_uri_domain, app_id, tenant_id) ON DELETE CASCADE +); + +CREATE INDEX IF NOT EXISTS tenant_default_required_factor_ids_tenant_id_index ON + tenant_required_secondary_factors (connection_uri_domain, app_id, tenant_id); + +ALTER TABLE totp_user_devices ADD COLUMN IF NOT EXISTS created_at BIGINT default 0; +ALTER TABLE totp_user_devices + ALTER COLUMN created_at DROP DEFAULT; +``` - If using MySQL +
- ```sql - CREATE TABLE IF NOT EXISTS tenant_first_factors ( - connection_uri_domain VARCHAR(256) DEFAULT '', - app_id VARCHAR(64) DEFAULT 'public', - tenant_id VARCHAR(64) DEFAULT 'public', - factor_id VARCHAR(128), - PRIMARY KEY (connection_uri_domain, app_id, tenant_id, factor_id), - FOREIGN KEY (connection_uri_domain, app_id, tenant_id) - REFERENCES tenant_configs (connection_uri_domain, app_id, tenant_id) ON DELETE CASCADE - ); +
- CREATE TABLE IF NOT EXISTS tenant_required_secondary_factors ( - connection_uri_domain VARCHAR(256) DEFAULT '', - app_id VARCHAR(64) DEFAULT 'public', - tenant_id VARCHAR(64) DEFAULT 'public', - factor_id VARCHAR(128), - PRIMARY KEY (connection_uri_domain, app_id, tenant_id, factor_id), - FOREIGN KEY (connection_uri_domain, app_id, tenant_id) - REFERENCES tenant_configs (connection_uri_domain, app_id, tenant_id) ON DELETE CASCADE - ); +If using MySQL - ALTER TABLE totp_user_devices ADD COLUMN created_at BIGINT UNSIGNED default 0; - ALTER TABLE totp_user_devices - ALTER COLUMN created_at DROP DEFAULT; - ``` +```sql +CREATE TABLE IF NOT EXISTS tenant_first_factors ( + connection_uri_domain VARCHAR(256) DEFAULT '', + app_id VARCHAR(64) DEFAULT 'public', + tenant_id VARCHAR(64) DEFAULT 'public', + factor_id VARCHAR(128), + PRIMARY KEY (connection_uri_domain, app_id, tenant_id, factor_id), + FOREIGN KEY (connection_uri_domain, app_id, tenant_id) + REFERENCES tenant_configs (connection_uri_domain, app_id, tenant_id) ON DELETE CASCADE +); + +CREATE TABLE IF NOT EXISTS tenant_required_secondary_factors ( + connection_uri_domain VARCHAR(256) DEFAULT '', + app_id VARCHAR(64) DEFAULT 'public', + tenant_id VARCHAR(64) DEFAULT 'public', + factor_id VARCHAR(128), + PRIMARY KEY (connection_uri_domain, app_id, tenant_id, factor_id), + FOREIGN KEY (connection_uri_domain, app_id, tenant_id) + REFERENCES tenant_configs (connection_uri_domain, app_id, tenant_id) ON DELETE CASCADE +); + +ALTER TABLE totp_user_devices ADD COLUMN created_at BIGINT UNSIGNED default 0; +ALTER TABLE totp_user_devices + ALTER COLUMN created_at DROP DEFAULT; +``` -
+
## [8.0.1] - 2024-03-11