1
pkg/coredata/migrations/20250313T110700Z.sql
Normal file
1
pkg/coredata/migrations/20250313T110700Z.sql
Normal file
@@ -0,0 +1 @@
|
||||
ALTER TABLE organizations RENAME COLUMN logo_url TO logo_object_key;
|
||||
@@ -27,12 +27,12 @@ import (
|
||||
|
||||
type (
|
||||
Organization struct {
|
||||
ID gid.GID `db:"id"`
|
||||
TenantID gid.TenantID `db:"tenant_id"`
|
||||
Name string `db:"name"`
|
||||
LogoURL string `db:"logo_url"`
|
||||
CreatedAt time.Time `db:"created_at"`
|
||||
UpdatedAt time.Time `db:"updated_at"`
|
||||
ID gid.GID `db:"id"`
|
||||
TenantID gid.TenantID `db:"tenant_id"`
|
||||
Name string `db:"name"`
|
||||
LogoObjectKey string `db:"logo_object_key"`
|
||||
CreatedAt time.Time `db:"created_at"`
|
||||
UpdatedAt time.Time `db:"updated_at"`
|
||||
}
|
||||
|
||||
Organizations []*Organization
|
||||
@@ -49,7 +49,7 @@ SELECT
|
||||
tenant_id,
|
||||
id,
|
||||
name,
|
||||
logo_url,
|
||||
logo_object_key,
|
||||
created_at,
|
||||
updated_at
|
||||
FROM
|
||||
@@ -89,19 +89,19 @@ INSERT INTO organizations (
|
||||
tenant_id,
|
||||
id,
|
||||
name,
|
||||
logo_url,
|
||||
logo_object_key,
|
||||
created_at,
|
||||
updated_at
|
||||
) VALUES (@tenant_id, @id, @name, @logo_url, @created_at, @updated_at)
|
||||
) VALUES (@tenant_id, @id, @name, @logo_object_key, @created_at, @updated_at)
|
||||
`
|
||||
|
||||
args := pgx.StrictNamedArgs{
|
||||
"tenant_id": o.TenantID,
|
||||
"id": o.ID,
|
||||
"name": o.Name,
|
||||
"logo_url": o.LogoURL,
|
||||
"created_at": o.CreatedAt,
|
||||
"updated_at": o.UpdatedAt,
|
||||
"tenant_id": o.TenantID,
|
||||
"id": o.ID,
|
||||
"name": o.Name,
|
||||
"logo_object_key": o.LogoObjectKey,
|
||||
"created_at": o.CreatedAt,
|
||||
"updated_at": o.UpdatedAt,
|
||||
}
|
||||
|
||||
_, err := conn.Exec(ctx, q, args)
|
||||
@@ -111,3 +111,38 @@ INSERT INTO organizations (
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o *Organization) Update(
|
||||
ctx context.Context,
|
||||
scope Scoper,
|
||||
conn pg.Conn,
|
||||
) error {
|
||||
q := `
|
||||
UPDATE organizations
|
||||
SET
|
||||
name = @name,
|
||||
logo_object_key = @logo_object_key,
|
||||
updated_at = @updated_at
|
||||
WHERE
|
||||
%s
|
||||
AND id = @id
|
||||
`
|
||||
|
||||
q = fmt.Sprintf(q, scope.SQLFragment())
|
||||
|
||||
args := pgx.StrictNamedArgs{
|
||||
"id": o.ID,
|
||||
"name": o.Name,
|
||||
"logo_object_key": o.LogoObjectKey,
|
||||
"updated_at": o.UpdatedAt,
|
||||
}
|
||||
|
||||
maps.Copy(args, scope.SQLArguments())
|
||||
|
||||
_, err := conn.Exec(ctx, q, args)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot update organization: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user