diff --git a/backend/gen/go/db/models.go b/backend/gen/go/db/models.go index d82495b6c3..6b08f0eff9 100644 --- a/backend/gen/go/db/models.go +++ b/backend/gen/go/db/models.go @@ -18,6 +18,17 @@ type NeosyncApiAccount struct { TemporalConfig *pg_models.TemporalConfig } +type NeosyncApiAccountApiKey struct { + ID pgtype.UUID + AccountID pgtype.UUID + KeyValue string + CreatedByID pgtype.UUID + UpdatedByID pgtype.UUID + CreatedAt pgtype.Timestamp + UpdatedAt pgtype.Timestamp + ExpiresAt pgtype.Timestamp +} + type NeosyncApiAccountInvite struct { ID pgtype.UUID AccountID pgtype.UUID diff --git a/backend/sql/postgresql/schema/20231110174028_account-api-keys.down.sql b/backend/sql/postgresql/schema/20231110174028_account-api-keys.down.sql new file mode 100644 index 0000000000..9ae77eda19 --- /dev/null +++ b/backend/sql/postgresql/schema/20231110174028_account-api-keys.down.sql @@ -0,0 +1 @@ +DROP TABLE IF EXISTS neosync_api.account_api_keys; diff --git a/backend/sql/postgresql/schema/20231110174028_account-api-keys.up.sql b/backend/sql/postgresql/schema/20231110174028_account-api-keys.up.sql new file mode 100644 index 0000000000..eeb526b452 --- /dev/null +++ b/backend/sql/postgresql/schema/20231110174028_account-api-keys.up.sql @@ -0,0 +1,22 @@ +CREATE TABLE IF NOT EXISTS neosync_api.account_api_keys ( + id uuid NOT NULL DEFAULT gen_random_uuid(), + account_id uuid NOT NULL, + + key_value text NOT NULL, + + created_by_id uuid NOT NULL, + updated_By_id uuid NOT NULL, + created_at timestamp NOT NULL DEFAULT now(), + updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + expires_at timestamp NOT NULL, + + CONSTRAINT account_api_keys_pkey PRIMARY KEY (id), + CONSTRAINT account_api_keys_account_id_key_value UNIQUE(account_id, key_value), + CONSTRAINT fk_account_api_keys_accounts_id FOREIGN KEY (account_id) REFERENCES neosync_api.accounts(id) ON DELETE CASCADE, + CONSTRAINT fk_account_api_keys_created_by_id FOREIGN KEY (created_by_id) REFERENCES neosync_api.users(id), + CONSTRAINT fk_account_api_keys_updated_by_id FOREIGN KEY (updated_by_id) REFERENCES neosync_api.users(id) +); +ALTER TABLE neosync_api.account_api_keys OWNER TO neosync_api_owner; +GRANT ALL ON TABLE neosync_api.account_api_keys TO neosync_api_owner; +GRANT INSERT, DELETE, UPDATE, SELECT ON TABLE neosync_api.account_api_keys TO neosync_api_readwrite; +GRANT SELECT ON TABLE neosync_api.account_api_keys TO neosync_api_readonly;