Skip to content

Commit

Permalink
satellite/db: add created_by column to api_keys and bucket_metainfos …
Browse files Browse the repository at this point in the history
…tables

Migrated api_keys and bucket_metainfos tables to include nullable created_by column.
this new column should be populated on create API key and bucket.

Issue:
#6855

Change-Id: Idab5cf8459510ff103f738c84e2b5a6e0cc67d0c
  • Loading branch information
VitaliiShpital committed Mar 21, 2024
1 parent fd0b23a commit 90437a6
Show file tree
Hide file tree
Showing 8 changed files with 957 additions and 52 deletions.
8 changes: 5 additions & 3 deletions satellite/satellitedb/dbx/project.dbx
Expand Up @@ -225,13 +225,15 @@ model api_key (
// head is restrictions for the api key.
field head blob
// name helps users to identify the purpose of the api key.
field name text (updatable)
field name text (updatable)
// secret is the macaroon secret.
field secret blob
// user_agent is the referred partner who created the project.
field user_agent blob (nullable)
field user_agent blob (nullable)
// created_at indicates when the api key was added.
field created_at timestamp (autoinsert)
field created_at timestamp (autoinsert)
// created_by is an UUID of the user who created this key.
field created_by user.id restrict (nullable)
)

create api_key ( )
Expand Down
3 changes: 3 additions & 0 deletions satellite/satellitedb/dbx/project_bucket.dbx
Expand Up @@ -69,6 +69,9 @@ model bucket_metainfo (
// 5 - Invalid, when there's no information about the placement.
// 6 - NR (no Russia, Belarus or other sanctioned country)
field placement int (nullable, updatable)

// created_by is an UUID of the user created this bucket.
field created_by user.id restrict (nullable)
)

create bucket_metainfo ()
Expand Down
172 changes: 124 additions & 48 deletions satellite/satellitedb/dbx/satellitedb.dbx.go

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions satellite/satellitedb/dbx/satellitedb.dbx.pgx.sql
Expand Up @@ -523,6 +523,7 @@ CREATE TABLE api_keys (
secret bytea NOT NULL,
user_agent bytea,
created_at timestamp with time zone NOT NULL,
created_by bytea REFERENCES users( id ),
PRIMARY KEY ( id ),
UNIQUE ( head ),
UNIQUE ( name, project_id )
Expand All @@ -545,6 +546,7 @@ CREATE TABLE bucket_metainfos (
default_redundancy_optimal_shares integer NOT NULL,
default_redundancy_total_shares integer NOT NULL,
placement integer,
created_by bytea REFERENCES users( id ),
PRIMARY KEY ( project_id, name )
);
CREATE TABLE project_invitations (
Expand Down
2 changes: 2 additions & 0 deletions satellite/satellitedb/dbx/satellitedb.dbx.pgxcockroach.sql
Expand Up @@ -523,6 +523,7 @@ CREATE TABLE api_keys (
secret bytea NOT NULL,
user_agent bytea,
created_at timestamp with time zone NOT NULL,
created_by bytea REFERENCES users( id ),
PRIMARY KEY ( id ),
UNIQUE ( head ),
UNIQUE ( name, project_id )
Expand All @@ -545,6 +546,7 @@ CREATE TABLE bucket_metainfos (
default_redundancy_optimal_shares integer NOT NULL,
default_redundancy_total_shares integer NOT NULL,
placement integer,
created_by bytea REFERENCES users( id ),
PRIMARY KEY ( project_id, name )
);
CREATE TABLE project_invitations (
Expand Down
9 changes: 9 additions & 0 deletions satellite/satellitedb/migrate.go
Expand Up @@ -2669,6 +2669,15 @@ func (db *satelliteDB) ProductionMigration() *migrate.Migration {
`ALTER TABLE stripe_customers ADD COLUMN billing_customer_id TEXT;`,
},
},
{
DB: &db.migrationDB,
Description: "add created_by column to api_keys and bucket_metainfos to be populated with a user id value",
Version: 264,
Action: migrate.SQL{
`ALTER TABLE api_keys ADD COLUMN created_by bytea REFERENCES users( id ) DEFAULT NULL;`,
`ALTER TABLE bucket_metainfos ADD COLUMN created_by bytea REFERENCES users( id ) DEFAULT NULL;`,
},
},
// NB: after updating testdata in `testdata`, run
// `go generate` to update `migratez.go`.
},
Expand Down
4 changes: 3 additions & 1 deletion satellite/satellitedb/migratez.go
Expand Up @@ -13,7 +13,7 @@ func (db *satelliteDB) testMigration() *migrate.Migration {
{
DB: &db.migrationDB,
Description: "Testing setup",
Version: 263,
Version: 264,
Action: migrate.SQL{`-- AUTOGENERATED BY storj.io/dbx
-- DO NOT EDIT
CREATE TABLE account_freeze_events (
Expand Down Expand Up @@ -539,6 +539,7 @@ CREATE TABLE api_keys (
secret bytea NOT NULL,
user_agent bytea,
created_at timestamp with time zone NOT NULL,
created_by bytea REFERENCES users( id ),
PRIMARY KEY ( id ),
UNIQUE ( head ),
UNIQUE ( name, project_id )
Expand All @@ -561,6 +562,7 @@ CREATE TABLE bucket_metainfos (
default_redundancy_optimal_shares integer NOT NULL,
default_redundancy_total_shares integer NOT NULL,
placement integer,
created_by bytea REFERENCES users( id ),
PRIMARY KEY ( project_id, name )
);
CREATE TABLE project_invitations (
Expand Down
809 changes: 809 additions & 0 deletions satellite/satellitedb/testdata/postgres.v264.sql

Large diffs are not rendered by default.

0 comments on commit 90437a6

Please sign in to comment.