-
Notifications
You must be signed in to change notification settings - Fork 344
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: map subjects/objects using UUIDv5
- Loading branch information
Showing
15 changed files
with
100 additions
and
90 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package migrate | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/ory/x/cmdx" | ||
"github.com/ory/x/flagx" | ||
"github.com/pkg/errors" | ||
"github.com/spf13/cobra" | ||
|
||
"github.com/ory/keto/internal/driver" | ||
"github.com/ory/keto/internal/persistence" | ||
"github.com/ory/keto/internal/persistence/sql/migrations" | ||
) | ||
|
||
func newMigrateUUIDMappingCmd() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "uuid-mapping", | ||
Short: "Migrate the non-UUID subject and object names to UUIDs.", | ||
Long: `Migrate the non-UUID subject and object names to UUIDs. | ||
This step only has to be executed once. | ||
Please ensure that you have a backup in case something goes wrong!"`, | ||
Args: cobra.NoArgs, | ||
RunE: func(cmd *cobra.Command, _ []string) error { | ||
reg, err := driver.NewDefaultRegistry(cmd.Context(), cmd.Flags(), false) | ||
if errors.Is(err, persistence.ErrNetworkMigrationsMissing) { | ||
_, _ = fmt.Fprintln(cmd.ErrOrStderr(), | ||
"Migrations were not applied yet, please apply them first using `keto migrate up`.") | ||
return cmdx.FailSilently(cmd) | ||
} else if err != nil { | ||
return err | ||
} | ||
|
||
if !flagx.MustGetBool(cmd, FlagYes) && | ||
!cmdx.AskForConfirmation( | ||
"Are you sure you want to migrate the subject and object names to UUIDs?", | ||
cmd.InOrStdin(), cmd.OutOrStdout()) { | ||
_, _ = fmt.Fprintln(cmd.OutOrStdout(), "OK, aborting.") | ||
return nil | ||
} | ||
|
||
migrator := migrations.NewToUUIDMappingMigrator(reg) | ||
return migrator.MigrateUUIDMappings(cmd.Context()) | ||
}, | ||
} | ||
RegisterYesFlag(cmd.Flags()) | ||
|
||
return cmd | ||
} |
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
9 changes: 3 additions & 6 deletions
9
...stence/sql/migrations/sql/20220110200400000000_create-uuid-mapping-table.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 |
---|---|---|
@@ -1,10 +1,7 @@ | ||
CREATE TABLE keto_uuid_mappings | ||
( | ||
id UUID NOT NULL, | ||
string_representation VARCHAR(255) NOT NULL CHECK (string_representation <> ''), | ||
id UUID NOT NULL, | ||
string_representation TEXT NOT NULL CHECK (string_representation <> ''), | ||
|
||
PRIMARY KEY (id), | ||
|
||
-- enforce uniqueness | ||
CONSTRAINT chk_keto_uuid_map_uniq UNIQUE (id, string_representation) | ||
PRIMARY KEY (id) | ||
); |
9 changes: 3 additions & 6 deletions
9
...ersistence/sql/migrations/sql/20220110200400000000_create-uuid-mapping-table.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 |
---|---|---|
@@ -1,10 +1,7 @@ | ||
CREATE TABLE keto_uuid_mappings | ||
( | ||
id VARCHAR(64) NOT NULL, | ||
string_representation VARCHAR(255) NOT NULL CHECK (string_representation <> ''), | ||
id VARCHAR(64) NOT NULL, | ||
string_representation TEXT NOT NULL CHECK (string_representation <> ''), | ||
|
||
PRIMARY KEY (id), | ||
|
||
-- enforce uniqueness | ||
CONSTRAINT chk_keto_uuid_map_uniq UNIQUE (id, string_representation) | ||
PRIMARY KEY (id) | ||
); |
9 changes: 3 additions & 6 deletions
9
...istence/sql/migrations/sql/20220110200400000000_create-uuid-mapping-table.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 |
---|---|---|
@@ -1,10 +1,7 @@ | ||
CREATE TABLE keto_uuid_mappings | ||
( | ||
id UUID NOT NULL, | ||
string_representation VARCHAR(255) NOT NULL CHECK (string_representation <> ''), | ||
id UUID NOT NULL, | ||
string_representation TEXT NOT NULL CHECK (string_representation <> ''), | ||
|
||
PRIMARY KEY (id), | ||
|
||
-- enforce uniqueness | ||
CONSTRAINT chk_keto_uuid_map_uniq UNIQUE (id, string_representation) | ||
PRIMARY KEY (id) | ||
); |
9 changes: 3 additions & 6 deletions
9
...sistence/sql/migrations/sql/20220110200400000000_create-uuid-mapping-table.sqlite3.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 |
---|---|---|
@@ -1,10 +1,7 @@ | ||
CREATE TABLE keto_uuid_mappings | ||
( | ||
id UUID NOT NULL, | ||
string_representation VARCHAR(255) NOT NULL CHECK (string_representation <> ''), | ||
id UUID NOT NULL, | ||
string_representation TEXT NOT NULL CHECK (string_representation <> ''), | ||
|
||
PRIMARY KEY (id), | ||
|
||
-- enforce uniqueness | ||
CONSTRAINT chk_keto_uuid_map_uniq UNIQUE (id, string_representation) | ||
PRIMARY KEY (id) | ||
); |
2 changes: 0 additions & 2 deletions
2
...stence/sql/migrations/sql/20220110200400000001_create-uuid-mapping-table.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 |
---|---|---|
@@ -1,2 +0,0 @@ | ||
|
||
CREATE INDEX keto_uuid_mappings_subject_ids_idx ON keto_uuid_mappings (string_representation); | ||
2 changes: 0 additions & 2 deletions
2
...ersistence/sql/migrations/sql/20220110200400000001_create-uuid-mapping-table.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 |
---|---|---|
@@ -1,2 +0,0 @@ | ||
|
||
CREATE INDEX keto_uuid_mappings_subject_ids_idx ON keto_uuid_mappings (string_representation); | ||
2 changes: 0 additions & 2 deletions
2
...istence/sql/migrations/sql/20220110200400000001_create-uuid-mapping-table.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 |
---|---|---|
@@ -1,2 +0,0 @@ | ||
|
||
CREATE INDEX keto_uuid_mappings_subject_ids_idx ON keto_uuid_mappings (string_representation); | ||
2 changes: 0 additions & 2 deletions
2
...sistence/sql/migrations/sql/20220110200400000001_create-uuid-mapping-table.sqlite3.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 |
---|---|---|
@@ -1,2 +0,0 @@ | ||
|
||
CREATE INDEX keto_uuid_mappings_subject_ids_idx ON keto_uuid_mappings (string_representation); | ||
13 changes: 4 additions & 9 deletions
13
...ersistence/sql/migrations/templates/20220110200400_create-uuid-mapping-table.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 |
---|---|---|
@@ -1,12 +1,7 @@ | ||
CREATE TABLE keto_uuid_mappings | ||
( | ||
id VARCHAR(64) NOT NULL, | ||
string_representation VARCHAR(255) NOT NULL CHECK (string_representation <> ''), | ||
id VARCHAR(64) NOT NULL, | ||
string_representation TEXT NOT NULL CHECK (string_representation <> ''), | ||
|
||
PRIMARY KEY (id), | ||
|
||
-- enforce uniqueness | ||
CONSTRAINT chk_keto_uuid_map_uniq UNIQUE (id, string_representation) | ||
); | ||
|
||
CREATE INDEX keto_uuid_mappings_subject_ids_idx ON keto_uuid_mappings (string_representation); | ||
PRIMARY KEY (id) | ||
); |
13 changes: 4 additions & 9 deletions
13
...rnal/persistence/sql/migrations/templates/20220110200400_create-uuid-mapping-table.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 |
---|---|---|
@@ -1,12 +1,7 @@ | ||
CREATE TABLE keto_uuid_mappings | ||
( | ||
id UUID NOT NULL, | ||
string_representation VARCHAR(255) NOT NULL CHECK (string_representation <> ''), | ||
id UUID NOT NULL, | ||
string_representation TEXT NOT NULL CHECK (string_representation <> ''), | ||
|
||
PRIMARY KEY (id), | ||
|
||
-- enforce uniqueness | ||
CONSTRAINT chk_keto_uuid_map_uniq UNIQUE (id, string_representation) | ||
); | ||
|
||
CREATE INDEX keto_uuid_mappings_subject_ids_idx ON keto_uuid_mappings (string_representation); | ||
PRIMARY KEY (id) | ||
); |
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