Skip to content

Commit

Permalink
Merge branch '7.0' into feat/multitenancy-dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
sattvikc committed May 23, 2024
2 parents 9e24ad0 + de70b57 commit d4967df
Showing 1 changed file with 132 additions and 27 deletions.
159 changes: 132 additions & 27 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,33 @@ CREATE INDEX app_id_to_user_id_user_id_index ON app_id_to_user_id (user_id);
SELECT concat('ALTER TABLE ', table_schema,'.',table_name,' DROP FOREIGN KEY ', constraint_name, ';')
FROM information_schema.table_constraints
WHERE constraint_type='FOREIGN KEY'
AND table_schema = DATABASE();
AND table_schema = DATABASE()
AND table_name in (
'all_auth_recipe_users',
'dashboard_user_sessions',
'dashboard_users',
'emailpassword_pswd_reset_tokens',
'emailpassword_users',
'emailverification_tokens',
'emailverification_verified_emails',
'jwt_signing_keys',
'key_value',
'passwordless_codes',
'passwordless_devices',
'passwordless_users',
'role_permissions',
'roles',
'session_access_token_signing_keys',
'session_info',
'thirdparty_users',
'totp_used_codes',
'totp_user_devices',
'totp_users',
'user_last_active',
'user_metadata',
'user_roles',
'userid_mapping'
);

DECLARE CONTINUE handler for NOT found SET done = true;
OPEN dropCur;
Expand All @@ -255,7 +281,7 @@ CREATE INDEX app_id_to_user_id_user_id_index ON app_id_to_user_id (user_id);
CLOSE dropCur;
END

---
--

CREATE PROCEDURE st_drop_all_pkeys()
BEGIN
Expand All @@ -265,7 +291,33 @@ CREATE INDEX app_id_to_user_id_user_id_index ON app_id_to_user_id (user_id);
SELECT concat('ALTER TABLE ', table_schema,'.',table_name,' DROP PRIMARY KEY ', ';')
FROM information_schema.table_constraints
WHERE constraint_type='PRIMARY KEY'
AND table_schema = DATABASE();
AND table_schema = DATABASE()
AND table_name in (
'all_auth_recipe_users',
'dashboard_user_sessions',
'dashboard_users',
'emailpassword_pswd_reset_tokens',
'emailpassword_users',
'emailverification_tokens',
'emailverification_verified_emails',
'jwt_signing_keys',
'key_value',
'passwordless_codes',
'passwordless_devices',
'passwordless_users',
'role_permissions',
'roles',
'session_access_token_signing_keys',
'session_info',
'thirdparty_users',
'totp_used_codes',
'totp_user_devices',
'totp_users',
'user_last_active',
'user_metadata',
'user_roles',
'userid_mapping'
);

DECLARE CONTINUE handler for NOT found SET done = true;
OPEN dropCur;
Expand All @@ -288,7 +340,7 @@ CREATE INDEX app_id_to_user_id_user_id_index ON app_id_to_user_id (user_id);
CLOSE dropCur;
END

---
--

CREATE PROCEDURE st_drop_all_keys()
BEGIN
Expand All @@ -298,7 +350,33 @@ CREATE INDEX app_id_to_user_id_user_id_index ON app_id_to_user_id (user_id);
SELECT concat('ALTER TABLE ', table_schema,'.',table_name,' DROP INDEX ', constraint_name, ';')
FROM information_schema.table_constraints
WHERE constraint_type='UNIQUE'
AND table_schema = DATABASE();
AND table_schema = DATABASE()
AND table_name in (
'all_auth_recipe_users',
'dashboard_user_sessions',
'dashboard_users',
'emailpassword_pswd_reset_tokens',
'emailpassword_users',
'emailverification_tokens',
'emailverification_verified_emails',
'jwt_signing_keys',
'key_value',
'passwordless_codes',
'passwordless_devices',
'passwordless_users',
'role_permissions',
'roles',
'session_access_token_signing_keys',
'session_info',
'thirdparty_users',
'totp_used_codes',
'totp_user_devices',
'totp_users',
'user_last_active',
'user_metadata',
'user_roles',
'userid_mapping'
);

DECLARE CONTINUE handler for NOT found SET done = true;
OPEN dropCur;
Expand All @@ -321,7 +399,7 @@ CREATE INDEX app_id_to_user_id_user_id_index ON app_id_to_user_id (user_id);
CLOSE dropCur;
END

---
--

CREATE PROCEDURE st_drop_all_indexes()
BEGIN
Expand All @@ -330,7 +408,34 @@ CREATE INDEX app_id_to_user_id_user_id_index ON app_id_to_user_id (user_id);
DECLARE dropCur CURSOR for
SELECT DISTINCT concat('ALTER TABLE ', table_schema, '.', table_name, ' DROP INDEX ', index_name, ';')
FROM information_schema.statistics
WHERE NON_UNIQUE = 1 AND table_schema = database();
WHERE NON_UNIQUE = 1
AND table_schema = database()
AND table_name in (
'all_auth_recipe_users',
'dashboard_user_sessions',
'dashboard_users',
'emailpassword_pswd_reset_tokens',
'emailpassword_users',
'emailverification_tokens',
'emailverification_verified_emails',
'jwt_signing_keys',
'key_value',
'passwordless_codes',
'passwordless_devices',
'passwordless_users',
'role_permissions',
'roles',
'session_access_token_signing_keys',
'session_info',
'thirdparty_users',
'totp_used_codes',
'totp_user_devices',
'totp_users',
'user_last_active',
'user_metadata',
'user_roles',
'userid_mapping'
);

DECLARE CONTINUE handler for NOT found SET done = true;
OPEN dropCur;
Expand All @@ -353,7 +458,7 @@ CREATE INDEX app_id_to_user_id_user_id_index ON app_id_to_user_id (user_id);
CLOSE dropCur;
END

---
--

CREATE PROCEDURE st_add_column_if_not_exists(
IN p_table_name varchar(50),
Expand Down Expand Up @@ -405,7 +510,7 @@ CREATE INDEX app_id_to_user_id_user_id_index ON app_id_to_user_id (user_id);
INSERT IGNORE INTO apps (app_id, created_at_time)
VALUES ('public', 0);

------------------------------------------------------------
--

CREATE TABLE IF NOT EXISTS tenants (
app_id VARCHAR(64) NOT NULL DEFAULT 'public',
Expand All @@ -423,7 +528,7 @@ CREATE INDEX app_id_to_user_id_user_id_index ON app_id_to_user_id (user_id);
INSERT IGNORE INTO tenants (app_id, tenant_id, created_at_time)
VALUES ('public', 'public', 0);

------------------------------------------------------------
--

CALL st_add_column_if_not_exists('key_value', 'app_id', 'VARCHAR(64)', 'NOT NULL DEFAULT \'public\'', @status_message);
CALL st_add_column_if_not_exists('key_value', 'tenant_id', 'VARCHAR(64)', 'NOT NULL DEFAULT \'public\'', @status_message);
Expand All @@ -435,7 +540,7 @@ CREATE INDEX app_id_to_user_id_user_id_index ON app_id_to_user_id (user_id);
ADD FOREIGN KEY (app_id, tenant_id)
REFERENCES tenants (app_id, tenant_id) ON DELETE CASCADE;

------------------------------------------------------------
--

CREATE TABLE IF NOT EXISTS app_id_to_user_id (
app_id VARCHAR(64) NOT NULL DEFAULT 'public',
Expand All @@ -454,7 +559,7 @@ CREATE INDEX app_id_to_user_id_user_id_index ON app_id_to_user_id (user_id);
SELECT user_id, recipe_id
FROM all_auth_recipe_users;

------------------------------------------------------------
--

CALL st_add_column_if_not_exists('all_auth_recipe_users', 'app_id', 'VARCHAR(64)', 'NOT NULL DEFAULT \'public\'', @status_message);
CALL st_add_column_if_not_exists('all_auth_recipe_users', 'tenant_id', 'VARCHAR(64)', 'NOT NULL DEFAULT \'public\'', @status_message);
Expand Down Expand Up @@ -487,7 +592,7 @@ CREATE INDEX app_id_to_user_id_user_id_index ON app_id_to_user_id (user_id);
ALTER TABLE tenant_configs
ADD PRIMARY KEY (connection_uri_domain, app_id, tenant_id);

------------------------------------------------------------
--

CREATE TABLE IF NOT EXISTS tenant_thirdparty_providers (
connection_uri_domain VARCHAR(256) DEFAULT '',
Expand Down Expand Up @@ -520,7 +625,7 @@ CREATE INDEX app_id_to_user_id_user_id_index ON app_id_to_user_id (user_id);
ADD 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_thirdparty_provider_clients (
connection_uri_domain VARCHAR(256) DEFAULT '',
Expand Down Expand Up @@ -557,7 +662,7 @@ CREATE INDEX app_id_to_user_id_user_id_index ON app_id_to_user_id (user_id);

CREATE INDEX session_expiry_index ON session_info (expires_at);

------------------------------------------------------------
--

CALL st_add_column_if_not_exists('session_access_token_signing_keys', 'app_id', 'VARCHAR(64)', 'NOT NULL DEFAULT \'public\'', @status_message);

Expand Down Expand Up @@ -590,7 +695,7 @@ CREATE INDEX app_id_to_user_id_user_id_index ON app_id_to_user_id (user_id);
ADD FOREIGN KEY (app_id)
REFERENCES apps (app_id) ON DELETE CASCADE;

------------------------------------------------------------
--

CALL st_add_column_if_not_exists('emailverification_tokens', 'app_id', 'VARCHAR(64)', 'NOT NULL DEFAULT \'public\'', @status_message);
CALL st_add_column_if_not_exists('emailverification_tokens', 'tenant_id', 'VARCHAR(64)', 'NOT NULL DEFAULT \'public\'', @status_message);
Expand Down Expand Up @@ -618,7 +723,7 @@ CREATE INDEX app_id_to_user_id_user_id_index ON app_id_to_user_id (user_id);
ADD FOREIGN KEY (app_id, user_id)
REFERENCES app_id_to_user_id (app_id, user_id) ON DELETE CASCADE;

-- ------------------------------------------------------------
-- --

CREATE TABLE IF NOT EXISTS emailpassword_user_to_tenant (
app_id VARCHAR(64) DEFAULT 'public',
Expand All @@ -640,7 +745,7 @@ CREATE INDEX app_id_to_user_id_user_id_index ON app_id_to_user_id (user_id);
INSERT IGNORE INTO emailpassword_user_to_tenant (user_id, email)
SELECT user_id, email FROM emailpassword_users;

------------------------------------------------------------
--

CALL st_add_column_if_not_exists('emailpassword_pswd_reset_tokens', 'app_id', 'VARCHAR(64)', 'NOT NULL DEFAULT \'public\'', @status_message);

Expand All @@ -667,7 +772,7 @@ CREATE INDEX app_id_to_user_id_user_id_index ON app_id_to_user_id (user_id);
ADD FOREIGN KEY (app_id, user_id)
REFERENCES app_id_to_user_id (app_id, user_id) ON DELETE CASCADE;

------------------------------------------------------------
--

CREATE TABLE IF NOT EXISTS passwordless_user_to_tenant (
app_id VARCHAR(64) DEFAULT 'public',
Expand All @@ -693,7 +798,7 @@ CREATE INDEX app_id_to_user_id_user_id_index ON app_id_to_user_id (user_id);
INSERT IGNORE INTO passwordless_user_to_tenant (user_id, email, phone_number)
SELECT user_id, email, phone_number FROM passwordless_users;

------------------------------------------------------------
--

CALL st_add_column_if_not_exists('passwordless_devices', 'app_id', 'VARCHAR(64)', 'NOT NULL DEFAULT \'public\'', @status_message);
CALL st_add_column_if_not_exists('passwordless_devices', 'tenant_id', 'VARCHAR(64)', 'NOT NULL DEFAULT \'public\'', @status_message);
Expand All @@ -709,7 +814,7 @@ CREATE INDEX app_id_to_user_id_user_id_index ON app_id_to_user_id (user_id);

CREATE INDEX passwordless_devices_phone_number_index ON passwordless_devices (app_id, tenant_id, phone_number);

------------------------------------------------------------
--

CALL st_add_column_if_not_exists('passwordless_codes', 'app_id', 'VARCHAR(64)', 'NOT NULL DEFAULT \'public\'', @status_message);
CALL st_add_column_if_not_exists('passwordless_codes', 'tenant_id', 'VARCHAR(64)', 'NOT NULL DEFAULT \'public\'', @status_message);
Expand Down Expand Up @@ -742,7 +847,7 @@ CREATE INDEX app_id_to_user_id_user_id_index ON app_id_to_user_id (user_id);

CREATE INDEX thirdparty_users_email_index ON thirdparty_users (app_id, email);

------------------------------------------------------------
--

CREATE TABLE IF NOT EXISTS thirdparty_user_to_tenant (
app_id VARCHAR(64) DEFAULT 'public',
Expand Down Expand Up @@ -796,7 +901,7 @@ CREATE INDEX app_id_to_user_id_user_id_index ON app_id_to_user_id (user_id);
ADD FOREIGN KEY (app_id)
REFERENCES apps (app_id) ON DELETE CASCADE;

------------------------------------------------------------
--

CALL st_add_column_if_not_exists('role_permissions', 'app_id', 'VARCHAR(64)', 'NOT NULL DEFAULT \'public\'', @status_message);

Expand All @@ -809,7 +914,7 @@ CREATE INDEX app_id_to_user_id_user_id_index ON app_id_to_user_id (user_id);

CREATE INDEX role_permissions_permission_index ON role_permissions (app_id, permission);

------------------------------------------------------------
--

CALL st_add_column_if_not_exists('user_roles', 'app_id', 'VARCHAR(64)', 'NOT NULL DEFAULT \'public\'', @status_message);
CALL st_add_column_if_not_exists('user_roles', 'tenant_id', 'VARCHAR(64)', 'NOT NULL DEFAULT \'public\'', @status_message);
Expand Down Expand Up @@ -853,7 +958,7 @@ CREATE INDEX app_id_to_user_id_user_id_index ON app_id_to_user_id (user_id);
ADD FOREIGN KEY (app_id)
REFERENCES apps (app_id) ON DELETE CASCADE;

------------------------------------------------------------
--

CALL st_add_column_if_not_exists('dashboard_user_sessions', 'app_id', 'VARCHAR(64)', 'NOT NULL DEFAULT \'public\'', @status_message);

Expand All @@ -877,7 +982,7 @@ CREATE INDEX app_id_to_user_id_user_id_index ON app_id_to_user_id (user_id);
ADD FOREIGN KEY (app_id)
REFERENCES apps (app_id) ON DELETE CASCADE;

------------------------------------------------------------
--

CALL st_add_column_if_not_exists('totp_user_devices', 'app_id', 'VARCHAR(64)', 'NOT NULL DEFAULT \'public\'', @status_message);

Expand All @@ -888,7 +993,7 @@ CREATE INDEX app_id_to_user_id_user_id_index ON app_id_to_user_id (user_id);
ADD FOREIGN KEY (app_id, user_id)
REFERENCES totp_users (app_id, user_id) ON DELETE CASCADE;

------------------------------------------------------------
--

CALL st_add_column_if_not_exists('totp_used_codes', 'app_id', 'VARCHAR(64)', 'NOT NULL DEFAULT \'public\'', @status_message);
CALL st_add_column_if_not_exists('totp_used_codes', 'tenant_id', 'VARCHAR(64)', 'NOT NULL DEFAULT \'public\'', @status_message);
Expand Down

0 comments on commit d4967df

Please sign in to comment.