Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…l-plugin into 7.0
  • Loading branch information
rishabhpoddar committed Jul 8, 2024
2 parents 3d85a5c + de70b57 commit 09a2d2e
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 @@ -218,7 +218,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 @@ -241,7 +267,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 @@ -251,7 +277,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 @@ -274,7 +326,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 @@ -284,7 +336,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 @@ -307,7 +385,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 @@ -316,7 +394,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 @@ -339,7 +444,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 @@ -391,7 +496,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 @@ -409,7 +514,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 @@ -421,7 +526,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 @@ -440,7 +545,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 @@ -473,7 +578,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 @@ -506,7 +611,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 @@ -543,7 +648,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 @@ -576,7 +681,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 @@ -604,7 +709,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 @@ -626,7 +731,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 @@ -653,7 +758,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 @@ -679,7 +784,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 @@ -695,7 +800,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 @@ -728,7 +833,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 @@ -782,7 +887,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 @@ -795,7 +900,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 @@ -839,7 +944,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 @@ -863,7 +968,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 @@ -874,7 +979,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 09a2d2e

Please sign in to comment.