-
Notifications
You must be signed in to change notification settings - Fork 976
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
feat: change primary key on identity_verifiable_addresses and identity_recovery_addresses #4139
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// Copyright © 2024 Ory Corp | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package gomigrations | ||
|
||
import ( | ||
"github.com/ory/x/popx" | ||
) | ||
|
||
var ChangeAddressesPK = []popx.Migration{} |
3 changes: 2 additions & 1 deletion
3
persistence/sql/migrations/sql/20210817181232000000_unique_credentials.sqlite3.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 |
---|---|---|
@@ -1 +1,2 @@ | ||
CREATE UNIQUE INDEX "identity_credential_identifiers_identifier_nid_uq_idx" ON "identity_credential_identifiers" (nid, identifier); | ||
DELETE FROM "identity_credential_identifiers"; -- This migration is destructive. | ||
CREATE UNIQUE INDEX "identity_credential_identifiers_identifier_nid_uq_idx" ON "identity_credential_identifiers" (nid, identifier); |
1 change: 1 addition & 0 deletions
1
...l/migrations/sql/20241001000000000000_identity_verifiable_addresses_pk.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 identity_verifiable_addresses ALTER PRIMARY KEY USING COLUMNS (id); |
1 change: 1 addition & 0 deletions
1
...sql/migrations/sql/20241001000000000000_identity_verifiable_addresses_pk.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 @@ | ||
ALTER TABLE identity_verifiable_addresses ALTER PRIMARY KEY USING COLUMNS (identity_id,id); |
7 changes: 7 additions & 0 deletions
7
...e/sql/migrations/sql/20241001000000000000_identity_verifiable_addresses_pk.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,7 @@ | ||
ALTER TABLE identity_verifiable_addresses | ||
DROP FOREIGN KEY identity_verifiable_addresses_ibfk_1; | ||
|
||
ALTER TABLE identity_verifiable_addresses | ||
DROP PRIMARY KEY, | ||
ADD PRIMARY KEY (id), | ||
ADD CONSTRAINT identity_verifiable_addresses_ibfk_1 FOREIGN KEY (identity_id) REFERENCES identities(id) ON DELETE CASCADE; |
3 changes: 3 additions & 0 deletions
3
...nce/sql/migrations/sql/20241001000000000000_identity_verifiable_addresses_pk.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,3 @@ | ||
ALTER TABLE identity_verifiable_addresses | ||
DROP PRIMARY KEY, | ||
ADD PRIMARY KEY (identity_id, id); |
3 changes: 3 additions & 0 deletions
3
...ql/migrations/sql/20241001000000000000_identity_verifiable_addresses_pk.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,3 @@ | ||
ALTER TABLE identity_verifiable_addresses | ||
DROP CONSTRAINT identity_verifiable_addresses_pkey, | ||
ADD PRIMARY KEY (id); |
17 changes: 17 additions & 0 deletions
17
.../sql/migrations/sql/20241001000000000000_identity_verifiable_addresses_pk.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,17 @@ | ||
CREATE UNIQUE INDEX identity_verifiable_addresses_id_uq_idx ON identity_verifiable_addresses (id); | ||
|
||
ALTER TABLE identity_verification_codes | ||
DROP CONSTRAINT identity_verification_codes_identity_verifiable_addresses_id_fk; | ||
|
||
ALTER TABLE identity_verification_tokens | ||
DROP CONSTRAINT identity_verification_tokens_identity_verifiable_address_i_fkey; | ||
|
||
ALTER TABLE identity_verifiable_addresses | ||
DROP CONSTRAINT identity_verifiable_addresses_pkey, | ||
ADD PRIMARY KEY (identity_id, id); | ||
|
||
ALTER TABLE identity_verification_codes | ||
ADD CONSTRAINT identity_verification_codes_identity_verifiable_addresses_id_fk FOREIGN KEY (identity_verifiable_address_id) REFERENCES identity_verifiable_addresses(id) ON DELETE CASCADE; | ||
|
||
ALTER TABLE identity_verification_tokens | ||
ADD CONSTRAINT identity_verification_tokens_identity_verifiable_address_i_fkey FOREIGN KEY (identity_verifiable_address_id) REFERENCES identity_verifiable_addresses(id) ON DELETE CASCADE; |
27 changes: 27 additions & 0 deletions
27
.../sql/migrations/sql/20241001000000000000_identity_verifiable_addresses_pk.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,27 @@ | ||
CREATE TABLE IF NOT EXISTS "_identity_verifiable_addresses_tmp" ( | ||
"id" TEXT PRIMARY KEY, | ||
"status" TEXT NOT NULL, | ||
"via" TEXT NOT NULL, | ||
"verified" bool NOT NULL, | ||
"value" TEXT NOT NULL, | ||
"verified_at" DATETIME, | ||
"identity_id" TEXT NOT NULL, | ||
"created_at" DATETIME NOT NULL, | ||
"updated_at" DATETIME NOT NULL, | ||
"nid" TEXT NOT NULL, | ||
FOREIGN KEY ("identity_id") REFERENCES "identities" ("id") ON UPDATE RESTRICT ON DELETE CASCADE, | ||
FOREIGN KEY ("nid") REFERENCES "networks" ("id") ON UPDATE RESTRICT ON DELETE CASCADE | ||
); | ||
|
||
INSERT INTO "_identity_verifiable_addresses_tmp" | ||
("id", "status", "via", "verified", "value", "verified_at", "identity_id", "created_at", "updated_at", "nid") | ||
SELECT | ||
"id", "status", "via", "verified", "value", "verified_at", "identity_id", "created_at", "updated_at", "nid" | ||
FROM "identity_verifiable_addresses"; | ||
|
||
DROP TABLE "identity_verifiable_addresses"; | ||
ALTER TABLE "_identity_verifiable_addresses_tmp" RENAME TO "identity_verifiable_addresses"; | ||
|
||
CREATE UNIQUE INDEX IF NOT EXISTS "identity_verifiable_addresses_status_via_uq_idx" ON "identity_verifiable_addresses" (nid, via, value); | ||
CREATE INDEX IF NOT EXISTS "identity_verifiable_addresses_status_via_idx" ON "identity_verifiable_addresses" (nid, via, value); | ||
CREATE INDEX IF NOT EXISTS identity_recovery_addresses_nid_id_idx ON identity_recovery_addresses (nid, id); |
30 changes: 30 additions & 0 deletions
30
...ce/sql/migrations/sql/20241001000000000000_identity_verifiable_addresses_pk.sqlite.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,30 @@ | ||
CREATE TABLE IF NOT EXISTS "_identity_verifiable_addresses_tmp" ( | ||
"id" TEXT NOT NULL, | ||
"status" TEXT NOT NULL, | ||
"via" TEXT NOT NULL, | ||
"verified" bool NOT NULL, | ||
"value" TEXT NOT NULL, | ||
"verified_at" DATETIME, | ||
"identity_id" TEXT NOT NULL, | ||
"created_at" DATETIME NOT NULL, | ||
"updated_at" DATETIME NOT NULL, | ||
"nid" TEXT NOT NULL, | ||
PRIMARY KEY ("identity_id","id"), | ||
FOREIGN KEY ("identity_id") REFERENCES "identities" ("id") ON UPDATE RESTRICT ON DELETE CASCADE, | ||
FOREIGN KEY ("nid") REFERENCES "networks" ("id") ON UPDATE RESTRICT ON DELETE CASCADE | ||
); | ||
|
||
INSERT INTO "_identity_verifiable_addresses_tmp" | ||
("id", "status", "via", "verified", "value", "verified_at", "identity_id", "created_at", "updated_at", "nid") | ||
SELECT | ||
"id", "status", "via", "verified", "value", "verified_at", "identity_id", "created_at", "updated_at", "nid" | ||
FROM "identity_verifiable_addresses"; | ||
|
||
DROP TABLE "identity_verifiable_addresses"; | ||
ALTER TABLE "_identity_verifiable_addresses_tmp" RENAME TO "identity_verifiable_addresses"; | ||
|
||
CREATE UNIQUE INDEX "identity_verifiable_addresses_status_via_uq_idx" ON "identity_verifiable_addresses" (nid, via, value); | ||
CREATE UNIQUE INDEX "identity_verifiable_addresses_id_uq_idx" ON "identity_verifiable_addresses" (id); | ||
CREATE INDEX "identity_verifiable_addresses_status_via_idx" ON "identity_verifiable_addresses" (nid, via, value); | ||
CREATE INDEX identity_verifiable_addresses_nid_id_idx ON identity_recovery_addresses (nid, id); | ||
CREATE INDEX identity_verifiable_addresses_id_nid_idx ON identity_recovery_addresses (id, nid); |
1 change: 1 addition & 0 deletions
1
...sql/migrations/sql/20241001000000000001_identity_recovery_addresses_pk.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 identity_recovery_addresses ALTER PRIMARY KEY USING COLUMNS (id); |
1 change: 1 addition & 0 deletions
1
...e/sql/migrations/sql/20241001000000000001_identity_recovery_addresses_pk.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 @@ | ||
ALTER TABLE identity_recovery_addresses ALTER PRIMARY KEY USING COLUMNS (identity_id, id); |
24 changes: 24 additions & 0 deletions
24
...nce/sql/migrations/sql/20241001000000000001_identity_recovery_addresses_pk.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,24 @@ | ||
ALTER TABLE identity_recovery_codes | ||
DROP FOREIGN KEY identity_recovery_codes_identity_recovery_addresses_id_fk, | ||
DROP FOREIGN KEY identity_recovery_codes_identity_id_fk; | ||
|
||
ALTER TABLE identity_recovery_tokens | ||
DROP FOREIGN KEY identity_recovery_tokens_identity_id_fk, | ||
DROP FOREIGN KEY identity_recovery_tokens_identity_recovery_addresses_id_fk; | ||
|
||
ALTER TABLE identity_recovery_addresses | ||
DROP FOREIGN KEY identity_recovery_addresses_ibfk_1; | ||
|
||
ALTER TABLE identity_recovery_addresses | ||
DROP PRIMARY KEY, | ||
ADD PRIMARY KEY (id), | ||
ADD CONSTRAINT identity_recovery_addresses_ibfk_1 FOREIGN KEY (identity_id) REFERENCES identities(id) ON DELETE CASCADE; | ||
|
||
ALTER TABLE identity_recovery_codes | ||
ADD CONSTRAINT identity_recovery_codes_identity_recovery_addresses_id_fk FOREIGN KEY (identity_recovery_address_id) REFERENCES identity_recovery_addresses (id) ON DELETE CASCADE, | ||
ADD CONSTRAINT identity_recovery_codes_identity_id_fk FOREIGN KEY (identity_id) REFERENCES identities (id) ON DELETE CASCADE; | ||
|
||
|
||
ALTER TABLE identity_recovery_tokens | ||
ADD CONSTRAINT identity_recovery_tokens_ibfk_1 FOREIGN KEY (identity_recovery_address_id) REFERENCES identity_recovery_addresses(id) ON DELETE CASCADE, | ||
ADD CONSTRAINT identity_recovery_tokens_identity_id_fk_idx FOREIGN KEY (identity_id) REFERENCES identities(id) ON DELETE CASCADE; |
19 changes: 19 additions & 0 deletions
19
...tence/sql/migrations/sql/20241001000000000001_identity_recovery_addresses_pk.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,19 @@ | ||
ALTER TABLE identity_recovery_codes | ||
DROP FOREIGN KEY identity_recovery_codes_identity_recovery_addresses_id_fk, | ||
DROP FOREIGN KEY identity_recovery_codes_identity_id_fk; | ||
|
||
ALTER TABLE identity_recovery_tokens | ||
DROP FOREIGN KEY identity_recovery_tokens_ibfk_1, | ||
DROP FOREIGN KEY identity_recovery_tokens_identity_id_fk_idx; | ||
|
||
ALTER TABLE identity_recovery_addresses | ||
DROP PRIMARY KEY, | ||
ADD PRIMARY KEY (identity_id, id); | ||
|
||
ALTER TABLE identity_recovery_codes | ||
ADD CONSTRAINT identity_recovery_codes_identity_recovery_addresses_id_fk FOREIGN KEY (identity_recovery_address_id) REFERENCES identity_recovery_addresses (id) ON DELETE CASCADE, | ||
ADD CONSTRAINT identity_recovery_codes_identity_id_fk FOREIGN KEY (identity_id) REFERENCES identities (id) ON DELETE CASCADE; -- this foreign key constraint was previously misnamed, this is the correct name | ||
|
||
ALTER TABLE identity_recovery_tokens | ||
ADD CONSTRAINT identity_recovery_tokens_identity_recovery_addresses_id_fk FOREIGN KEY (identity_recovery_address_id) REFERENCES identity_recovery_addresses(id) ON DELETE CASCADE, | ||
ADD CONSTRAINT identity_recovery_tokens_identity_id_fk FOREIGN KEY (identity_id) REFERENCES identities(id) ON DELETE CASCADE; |
3 changes: 3 additions & 0 deletions
3
.../sql/migrations/sql/20241001000000000001_identity_recovery_addresses_pk.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,3 @@ | ||
ALTER TABLE identity_recovery_addresses | ||
DROP CONSTRAINT identity_recovery_addresses_pkey, | ||
ADD PRIMARY KEY (id); |
17 changes: 17 additions & 0 deletions
17
...ce/sql/migrations/sql/20241001000000000001_identity_recovery_addresses_pk.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,17 @@ | ||
CREATE UNIQUE INDEX identity_recovery_addresses_id_uq_idx ON identity_recovery_addresses (id); | ||
|
||
ALTER TABLE identity_recovery_codes | ||
DROP CONSTRAINT identity_recovery_codes_identity_recovery_addresses_id_fk; | ||
|
||
ALTER TABLE identity_recovery_tokens | ||
DROP CONSTRAINT identity_recovery_tokens_identity_recovery_address_id_fkey; | ||
|
||
ALTER TABLE identity_recovery_addresses | ||
DROP CONSTRAINT identity_recovery_addresses_pkey, | ||
ADD PRIMARY KEY (identity_id, id); | ||
|
||
ALTER TABLE identity_recovery_codes | ||
ADD CONSTRAINT identity_recovery_codes_identity_recovery_addresses_id_fk FOREIGN KEY (identity_recovery_address_id) REFERENCES identity_recovery_addresses(id) ON DELETE CASCADE; | ||
|
||
ALTER TABLE identity_recovery_tokens | ||
ADD CONSTRAINT identity_recovery_tokens_identity_recovery_address_id_fkey FOREIGN KEY (identity_recovery_address_id) REFERENCES identity_recovery_addresses(id) ON DELETE CASCADE; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does mysql not have a unique index for the id?