fix: populate default created_by and add not-null constraint in templates (#2290)

This commit is contained in:
Abhineet Jain
2022-06-13 17:25:06 +00:00
committed by GitHub
parent 49f857806f
commit a91482cb25
12 changed files with 28 additions and 31 deletions
+1 -1
View File
@@ -249,7 +249,7 @@ CREATE TABLE templates (
description character varying(128) DEFAULT ''::character varying NOT NULL,
max_ttl bigint DEFAULT '604800000000000'::bigint NOT NULL,
min_autostart_interval bigint DEFAULT '3600000000000'::bigint NOT NULL,
created_by uuid
created_by uuid NOT NULL
);
CREATE TABLE users (
@@ -0,0 +1 @@
ALTER TABLE ONLY templates ALTER COLUMN created_by DROP NOT NULL;
@@ -0,0 +1,14 @@
UPDATE
templates
SET
created_by = (
SELECT user_id FROM organization_members
WHERE organization_members.organization_id = templates.organization_id
ORDER BY created_at
LIMIT 1
)
WHERE
created_by IS NULL;
ALTER TABLE ONLY templates ALTER COLUMN created_by SET NOT NULL;
+1 -1
View File
@@ -438,7 +438,7 @@ type Template struct {
Description string `db:"description" json:"description"`
MaxTtl int64 `db:"max_ttl" json:"max_ttl"`
MinAutostartInterval int64 `db:"min_autostart_interval" json:"min_autostart_interval"`
CreatedBy uuid.NullUUID `db:"created_by" json:"created_by"`
CreatedBy uuid.UUID `db:"created_by" json:"created_by"`
}
type TemplateVersion struct {
+1 -1
View File
@@ -1797,7 +1797,7 @@ type InsertTemplateParams struct {
Description string `db:"description" json:"description"`
MaxTtl int64 `db:"max_ttl" json:"max_ttl"`
MinAutostartInterval int64 `db:"min_autostart_interval" json:"min_autostart_interval"`
CreatedBy uuid.NullUUID `db:"created_by" json:"created_by"`
CreatedBy uuid.UUID `db:"created_by" json:"created_by"`
}
func (q *sqlQuerier) InsertTemplate(ctx context.Context, arg InsertTemplateParams) (Template, error) {