diff --git a/database/migrations/000063_user_invites.down.sql b/database/migrations/000063_user_invites.down.sql new file mode 100644 index 0000000000..c7b40f7d93 --- /dev/null +++ b/database/migrations/000063_user_invites.down.sql @@ -0,0 +1,25 @@ +-- Copyright 2024 Stacklok, Inc +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. + +BEGIN; + +-- drop the index on the project column +DROP INDEX IF EXISTS idx_user_invites_project; +-- drop the index on the email column +DROP INDEX IF EXISTS idx_user_invites_email; + +-- drop the user_invites table +DROP TABLE IF EXISTS user_invites; + +COMMIT; diff --git a/database/migrations/000063_user_invites.up.sql b/database/migrations/000063_user_invites.up.sql new file mode 100644 index 0000000000..3f60203df2 --- /dev/null +++ b/database/migrations/000063_user_invites.up.sql @@ -0,0 +1,32 @@ +-- Copyright 2024 Stacklok, Inc +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. + +BEGIN; + +CREATE TABLE IF NOT EXISTS user_invites ( + code TEXT NOT NULL PRIMARY KEY, + email TEXT NOT NULL, + role TEXT NOT NULL DEFAULT 'viewer', + project UUID NOT NULL REFERENCES projects(id) ON DELETE CASCADE, + sponsor INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE, + created_at TIMESTAMP NOT NULL DEFAULT NOW(), + updated_at TIMESTAMP NOT NULL DEFAULT NOW() +); + +-- create an index on the project column +CREATE INDEX IF NOT EXISTS idx_user_invites_project ON user_invites(project); +-- create an index on the email column +CREATE INDEX IF NOT EXISTS idx_user_invites_email ON user_invites(email); + +COMMIT; diff --git a/internal/db/models.go b/internal/db/models.go index 57e08af417..823a4dd162 100644 --- a/internal/db/models.go +++ b/internal/db/models.go @@ -693,3 +693,13 @@ type User struct { CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` } + +type UserInvite struct { + Code string `json:"code"` + Email string `json:"email"` + Role string `json:"role"` + Project uuid.UUID `json:"project"` + Sponsor int32 `json:"sponsor"` + CreatedAt time.Time `json:"created_at"` + UpdatedAt time.Time `json:"updated_at"` +}