forked from ory/hydra
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: deprecate autoincrement primary key in hydra_client
This is the first step towards resolving ory#2781. The issue will be resolved when we remove the deprecated column.
- Loading branch information
1 parent
8373bba
commit 26aa373
Showing
17 changed files
with
368 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
persistence/sql/migratest/testdata/20211004110001_testdata.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
INSERT INTO hydra_client | ||
( | ||
pk_new, | ||
pk_deprecated, | ||
id, | ||
client_name, | ||
client_secret, | ||
redirect_uris, | ||
grant_types, | ||
response_types, | ||
scope, | ||
owner, | ||
policy_uri, | ||
tos_uri, | ||
client_uri, | ||
logo_uri, | ||
contacts, | ||
client_secret_expires_at, | ||
sector_identifier_uri, | ||
jwks, | ||
jwks_uri, | ||
request_uris, | ||
token_endpoint_auth_method, | ||
request_object_signing_alg, | ||
userinfo_signed_response_alg, | ||
subject_type, | ||
allowed_cors_origins, | ||
audience, | ||
created_at, | ||
updated_at, | ||
frontchannel_logout_uri, | ||
frontchannel_logout_session_required, | ||
post_logout_redirect_uris, | ||
backchannel_logout_uri, | ||
backchannel_logout_session_required, | ||
metadata, | ||
token_endpoint_auth_signing_alg | ||
) | ||
VALUES | ||
('08f4a4b7-6601-4fd7-bb7f-29ec0681b86d', | ||
0, | ||
'client-20', | ||
'Client 20', | ||
'secret-20', | ||
'http://redirect/20_1', | ||
'grant-20_1', | ||
'response-20_1', | ||
'scope-20', | ||
'owner-20', | ||
'http://policy/20', | ||
'http://tos/20', | ||
'http://client/20', | ||
'http://logo/20', | ||
'contact-20_1', | ||
0, | ||
'http://sector_id/20', | ||
'', | ||
'http://jwks/20', | ||
'http://request/20_1', | ||
'token_auth-20', | ||
'r_alg-20', | ||
'u_alg-20', | ||
'subject-20', | ||
'http://cors/20_1', | ||
'autdience-20_1', | ||
now(), | ||
now(), | ||
'http://front_logout/20', | ||
true, | ||
'http://post_redirect/20_1', | ||
'http://back_logout/20', | ||
true, | ||
'{"migration": "20"}', | ||
'' | ||
); |
1 change: 1 addition & 0 deletions
1
persistence/sql/migrations/20211004110001000000_change_client_primary_key.cockroach.down.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ALTER TABLE hydra_client DROP CONSTRAINT "primary", ADD CONSTRAINT "primary" PRIMARY KEY (pk_deprecated); |
2 changes: 2 additions & 0 deletions
2
persistence/sql/migrations/20211004110001000000_change_client_primary_key.cockroach.up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
ALTER TABLE hydra_client RENAME pk TO pk_deprecated; | ||
ALTER TABLE hydra_client ADD pk_new UUID NOT NULL DEFAULT gen_random_uuid(); |
3 changes: 3 additions & 0 deletions
3
persistence/sql/migrations/20211004110001000000_change_client_primary_key.mysql.down.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
ALTER TABLE hydra_client CHANGE COLUMN pk_deprecated pk INT UNSIGNED AUTO_INCREMENT; | ||
ALTER TABLE hydra_client DROP PRIMARY KEY, ADD PRIMARY KEY (pk); | ||
ALTER TABLE hydra_client DROP pk_new; |
7 changes: 7 additions & 0 deletions
7
persistence/sql/migrations/20211004110001000000_change_client_primary_key.mysql.up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
ALTER TABLE hydra_client CHANGE COLUMN pk pk_deprecated INT UNSIGNED; | ||
ALTER TABLE hydra_client ADD COLUMN pk_new CHAR(36); | ||
UPDATE hydra_client SET pk_new = (SELECT uuid()); | ||
ALTER TABLE hydra_client ALTER pk_new DROP DEFAULT; | ||
ALTER TABLE hydra_client DROP PRIMARY KEY, ADD PRIMARY KEY (pk_new); | ||
ALTER TABLE hydra_client ADD KEY (pk_deprecated); | ||
ALTER TABLE hydra_client CHANGE COLUMN pk_deprecated pk_deprecated INT UNSIGNED AUTO_INCREMENT; |
4 changes: 4 additions & 0 deletions
4
persistence/sql/migrations/20211004110001000000_change_client_primary_key.postgres.down.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
ALTER TABLE hydra_client RENAME pk_deprecated TO pk; | ||
ALTER TABLE hydra_client DROP CONSTRAINT hydra_client_pkey; | ||
ALTER TABLE hydra_client ADD PRIMARY KEY (pk); | ||
ALTER TABLE hydra_client DROP pk_new; |
16 changes: 16 additions & 0 deletions
16
persistence/sql/migrations/20211004110001000000_change_client_primary_key.postgres.up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
ALTER TABLE hydra_client RENAME pk TO pk_deprecated; | ||
-- UUID generation based on https://stackoverflow.com/a/21327318/12723442 | ||
ALTER TABLE hydra_client ADD COLUMN pk_new UUID DEFAULT uuid_in( | ||
overlay( | ||
overlay( | ||
md5(random()::text || ':' || clock_timestamp()::text) | ||
placing '4' | ||
from 13 | ||
) | ||
placing to_hex(floor(random()*(11-8+1) + 8)::int)::text | ||
from 17 | ||
)::cstring | ||
); | ||
ALTER TABLE hydra_client ALTER pk_new DROP DEFAULT; | ||
ALTER TABLE hydra_client DROP CONSTRAINT hydra_client_pkey; | ||
ALTER TABLE hydra_client ADD PRIMARY KEY (pk_new); |
115 changes: 115 additions & 0 deletions
115
persistence/sql/migrations/20211004110001000000_change_client_primary_key.sqlite.down.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
CREATE TABLE "_hydra_client_tmp" | ||
( | ||
id VARCHAR(255) NOT NULL, | ||
client_name TEXT NOT NULL, | ||
client_secret TEXT NOT NULL, | ||
redirect_uris TEXT NOT NULL, | ||
grant_types TEXT NOT NULL, | ||
response_types TEXT NOT NULL, | ||
scope TEXT NOT NULL, | ||
owner TEXT NOT NULL, | ||
policy_uri TEXT NOT NULL, | ||
tos_uri TEXT NOT NULL, | ||
client_uri TEXT NOT NULL, | ||
logo_uri TEXT NOT NULL, | ||
contacts TEXT NOT NULL, | ||
client_secret_expires_at INTEGER NOT NULL DEFAULT 0, | ||
sector_identifier_uri TEXT NOT NULL, | ||
jwks TEXT NOT NULL, | ||
jwks_uri TEXT NOT NULL, | ||
request_uris TEXT NOT NULL, | ||
token_endpoint_auth_method VARCHAR(25) NOT NULL DEFAULT '', | ||
request_object_signing_alg VARCHAR(10) NOT NULL DEFAULT '', | ||
userinfo_signed_response_alg VARCHAR(10) NOT NULL DEFAULT '', | ||
subject_type VARCHAR(15) NOT NULL DEFAULT '', | ||
allowed_cors_origins TEXT NOT NULL, | ||
pk INTEGER PRIMARY KEY, | ||
audience TEXT NOT NULL, | ||
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
frontchannel_logout_uri TEXT NOT NULL DEFAULT '', | ||
frontchannel_logout_session_required INTEGER NOT NULL DEFAULT false, | ||
post_logout_redirect_uris TEXT NOT NULL DEFAULT '', | ||
backchannel_logout_uri TEXT NOT NULL DEFAULT '', | ||
backchannel_logout_session_required INTEGER NOT NULL DEFAULT false, | ||
metadata TEXT NOT NULL DEFAULT '{}', | ||
token_endpoint_auth_signing_alg VARCHAR(10) NOT NULL DEFAULT '' | ||
); | ||
|
||
INSERT INTO "_hydra_client_tmp" ( | ||
id, | ||
client_name, | ||
client_secret, | ||
redirect_uris, | ||
grant_types, | ||
response_types, | ||
scope, | ||
owner, | ||
policy_uri, | ||
tos_uri, | ||
client_uri, | ||
logo_uri, | ||
contacts, | ||
client_secret_expires_at, | ||
sector_identifier_uri, | ||
jwks, | ||
jwks_uri, | ||
request_uris, | ||
token_endpoint_auth_method, | ||
request_object_signing_alg, | ||
userinfo_signed_response_alg, | ||
subject_type, | ||
allowed_cors_origins, | ||
pk, | ||
audience, | ||
created_at, | ||
updated_at, | ||
frontchannel_logout_uri, | ||
frontchannel_logout_session_required, | ||
post_logout_redirect_uris, | ||
backchannel_logout_uri, | ||
backchannel_logout_session_required, | ||
metadata, | ||
token_endpoint_auth_signing_alg | ||
) SELECT | ||
id, | ||
client_name, | ||
client_secret, | ||
redirect_uris, | ||
grant_types, | ||
response_types, | ||
scope, | ||
owner, | ||
policy_uri, | ||
tos_uri, | ||
client_uri, | ||
logo_uri, | ||
contacts, | ||
client_secret_expires_at, | ||
sector_identifier_uri, | ||
jwks, | ||
jwks_uri, | ||
request_uris, | ||
token_endpoint_auth_method, | ||
request_object_signing_alg, | ||
userinfo_signed_response_alg, | ||
subject_type, | ||
allowed_cors_origins, | ||
pk_deprecated, | ||
audience, | ||
created_at, | ||
updated_at, | ||
frontchannel_logout_uri, | ||
frontchannel_logout_session_required, | ||
post_logout_redirect_uris, | ||
backchannel_logout_uri, | ||
backchannel_logout_session_required, | ||
metadata, | ||
token_endpoint_auth_signing_alg | ||
FROM "hydra_client"; | ||
|
||
DROP INDEX hydra_client_id_idx; | ||
DROP TABLE "hydra_client"; | ||
ALTER TABLE "_hydra_client_tmp" RENAME TO "hydra_client"; | ||
|
||
CREATE UNIQUE INDEX hydra_client_id_idx ON hydra_client (id); |
Oops, something went wrong.