forked from wrenn/wrenn
v0.1.0 (#17)
This commit is contained in:
@ -171,7 +171,7 @@ CREATE TABLE audit_logs (
|
||||
metadata JSONB NOT NULL DEFAULT '{}',
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
||||
);
|
||||
CREATE INDEX idx_audit_logs_team_time ON audit_logs(team_id, created_at DESC);
|
||||
CREATE INDEX idx_audit_logs_team_time ON audit_logs(team_id, created_at DESC, id DESC);
|
||||
CREATE INDEX idx_audit_logs_team_resource ON audit_logs(team_id, resource_type, created_at DESC);
|
||||
|
||||
-- sandbox_metrics_snapshots
|
||||
|
||||
17
db/migrations/20260411182550_template_defaults.sql
Normal file
17
db/migrations/20260411182550_template_defaults.sql
Normal file
@ -0,0 +1,17 @@
|
||||
-- +goose Up
|
||||
ALTER TABLE templates
|
||||
ADD COLUMN default_user TEXT NOT NULL DEFAULT 'root',
|
||||
ADD COLUMN default_env JSONB NOT NULL DEFAULT '{}';
|
||||
|
||||
ALTER TABLE template_builds
|
||||
ADD COLUMN default_user TEXT NOT NULL DEFAULT 'root',
|
||||
ADD COLUMN default_env JSONB NOT NULL DEFAULT '{}';
|
||||
|
||||
-- +goose Down
|
||||
ALTER TABLE template_builds
|
||||
DROP COLUMN default_env,
|
||||
DROP COLUMN default_user;
|
||||
|
||||
ALTER TABLE templates
|
||||
DROP COLUMN default_env,
|
||||
DROP COLUMN default_user;
|
||||
12
db/migrations/20260412213141_seed_platform_team.sql
Normal file
12
db/migrations/20260412213141_seed_platform_team.sql
Normal file
@ -0,0 +1,12 @@
|
||||
-- +goose Up
|
||||
|
||||
-- Seed the platform team row. This is the sentinel team (all-zeros UUID) that
|
||||
-- owns platform-wide resources: global templates, admin-created capsules, etc.
|
||||
-- No user can become a member of this team — it exists solely to satisfy
|
||||
-- foreign key constraints and to act as a namespace for platform resources.
|
||||
INSERT INTO teams (id, name, slug)
|
||||
VALUES ('00000000-0000-0000-0000-000000000000', 'Platform', 'platform')
|
||||
ON CONFLICT (id) DO NOTHING;
|
||||
|
||||
-- +goose Down
|
||||
DELETE FROM teams WHERE id = '00000000-0000-0000-0000-000000000000';
|
||||
7
db/migrations/20260414213729_add_user_active_deleted.sql
Normal file
7
db/migrations/20260414213729_add_user_active_deleted.sql
Normal file
@ -0,0 +1,7 @@
|
||||
-- +goose Up
|
||||
ALTER TABLE users ADD COLUMN is_active BOOLEAN NOT NULL DEFAULT TRUE;
|
||||
ALTER TABLE users ADD COLUMN deleted_at TIMESTAMPTZ;
|
||||
|
||||
-- +goose Down
|
||||
ALTER TABLE users DROP COLUMN deleted_at;
|
||||
ALTER TABLE users DROP COLUMN is_active;
|
||||
9
db/migrations/20260415134310_add_metadata.sql
Normal file
9
db/migrations/20260415134310_add_metadata.sql
Normal file
@ -0,0 +1,9 @@
|
||||
-- +goose Up
|
||||
ALTER TABLE sandboxes ADD COLUMN metadata JSONB NOT NULL DEFAULT '{}';
|
||||
ALTER TABLE templates ADD COLUMN metadata JSONB NOT NULL DEFAULT '{}';
|
||||
ALTER TABLE template_builds ADD COLUMN metadata JSONB NOT NULL DEFAULT '{}';
|
||||
|
||||
-- +goose Down
|
||||
ALTER TABLE sandboxes DROP COLUMN metadata;
|
||||
ALTER TABLE templates DROP COLUMN metadata;
|
||||
ALTER TABLE template_builds DROP COLUMN metadata;
|
||||
@ -0,0 +1,15 @@
|
||||
-- +goose Up
|
||||
ALTER TABLE users ADD COLUMN status TEXT NOT NULL DEFAULT 'active';
|
||||
|
||||
-- Backfill from existing columns.
|
||||
UPDATE users SET status = 'deleted' WHERE deleted_at IS NOT NULL;
|
||||
UPDATE users SET status = 'disabled' WHERE is_active = false AND deleted_at IS NULL;
|
||||
|
||||
ALTER TABLE users DROP COLUMN is_active;
|
||||
|
||||
-- +goose Down
|
||||
ALTER TABLE users ADD COLUMN is_active BOOLEAN NOT NULL DEFAULT TRUE;
|
||||
|
||||
UPDATE users SET is_active = false WHERE status IN ('inactive', 'disabled', 'deleted');
|
||||
|
||||
ALTER TABLE users DROP COLUMN status;
|
||||
72
db/migrations/20260415221116_cascade_user_delete.sql
Normal file
72
db/migrations/20260415221116_cascade_user_delete.sql
Normal file
@ -0,0 +1,72 @@
|
||||
-- +goose Up
|
||||
|
||||
-- users_teams: remove membership when user is deleted
|
||||
ALTER TABLE users_teams DROP CONSTRAINT users_teams_user_id_fkey;
|
||||
ALTER TABLE users_teams ADD CONSTRAINT users_teams_user_id_fkey
|
||||
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE;
|
||||
|
||||
-- oauth_providers: remove auth links when user is deleted
|
||||
ALTER TABLE oauth_providers DROP CONSTRAINT oauth_providers_user_id_fkey;
|
||||
ALTER TABLE oauth_providers ADD CONSTRAINT oauth_providers_user_id_fkey
|
||||
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE;
|
||||
|
||||
-- admin_permissions: remove permissions when user is deleted
|
||||
ALTER TABLE admin_permissions DROP CONSTRAINT admin_permissions_user_id_fkey;
|
||||
ALTER TABLE admin_permissions ADD CONSTRAINT admin_permissions_user_id_fkey
|
||||
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE;
|
||||
|
||||
-- team_api_keys.created_by: make nullable, SET NULL on user delete
|
||||
ALTER TABLE team_api_keys ALTER COLUMN created_by DROP NOT NULL;
|
||||
ALTER TABLE team_api_keys DROP CONSTRAINT team_api_keys_created_by_fkey;
|
||||
ALTER TABLE team_api_keys ADD CONSTRAINT team_api_keys_created_by_fkey
|
||||
FOREIGN KEY (created_by) REFERENCES users(id) ON DELETE SET NULL;
|
||||
|
||||
-- hosts.created_by: make nullable, SET NULL on user delete
|
||||
ALTER TABLE hosts ALTER COLUMN created_by DROP NOT NULL;
|
||||
ALTER TABLE hosts DROP CONSTRAINT hosts_created_by_fkey;
|
||||
ALTER TABLE hosts ADD CONSTRAINT hosts_created_by_fkey
|
||||
FOREIGN KEY (created_by) REFERENCES users(id) ON DELETE SET NULL;
|
||||
|
||||
-- host_tokens.created_by: make nullable, SET NULL on user delete
|
||||
ALTER TABLE host_tokens ALTER COLUMN created_by DROP NOT NULL;
|
||||
ALTER TABLE host_tokens DROP CONSTRAINT host_tokens_created_by_fkey;
|
||||
ALTER TABLE host_tokens ADD CONSTRAINT host_tokens_created_by_fkey
|
||||
FOREIGN KEY (created_by) REFERENCES users(id) ON DELETE SET NULL;
|
||||
|
||||
-- +goose Down
|
||||
|
||||
-- Revert host_tokens.created_by
|
||||
ALTER TABLE host_tokens DROP CONSTRAINT host_tokens_created_by_fkey;
|
||||
UPDATE host_tokens SET created_by = '00000000-0000-0000-0000-000000000000' WHERE created_by IS NULL;
|
||||
ALTER TABLE host_tokens ALTER COLUMN created_by SET NOT NULL;
|
||||
ALTER TABLE host_tokens ADD CONSTRAINT host_tokens_created_by_fkey
|
||||
FOREIGN KEY (created_by) REFERENCES users(id);
|
||||
|
||||
-- Revert hosts.created_by
|
||||
ALTER TABLE hosts DROP CONSTRAINT hosts_created_by_fkey;
|
||||
UPDATE hosts SET created_by = '00000000-0000-0000-0000-000000000000' WHERE created_by IS NULL;
|
||||
ALTER TABLE hosts ALTER COLUMN created_by SET NOT NULL;
|
||||
ALTER TABLE hosts ADD CONSTRAINT hosts_created_by_fkey
|
||||
FOREIGN KEY (created_by) REFERENCES users(id);
|
||||
|
||||
-- Revert team_api_keys.created_by
|
||||
ALTER TABLE team_api_keys DROP CONSTRAINT team_api_keys_created_by_fkey;
|
||||
UPDATE team_api_keys SET created_by = '00000000-0000-0000-0000-000000000000' WHERE created_by IS NULL;
|
||||
ALTER TABLE team_api_keys ALTER COLUMN created_by SET NOT NULL;
|
||||
ALTER TABLE team_api_keys ADD CONSTRAINT team_api_keys_created_by_fkey
|
||||
FOREIGN KEY (created_by) REFERENCES users(id);
|
||||
|
||||
-- Revert admin_permissions
|
||||
ALTER TABLE admin_permissions DROP CONSTRAINT admin_permissions_user_id_fkey;
|
||||
ALTER TABLE admin_permissions ADD CONSTRAINT admin_permissions_user_id_fkey
|
||||
FOREIGN KEY (user_id) REFERENCES users(id);
|
||||
|
||||
-- Revert oauth_providers
|
||||
ALTER TABLE oauth_providers DROP CONSTRAINT oauth_providers_user_id_fkey;
|
||||
ALTER TABLE oauth_providers ADD CONSTRAINT oauth_providers_user_id_fkey
|
||||
FOREIGN KEY (user_id) REFERENCES users(id);
|
||||
|
||||
-- Revert users_teams
|
||||
ALTER TABLE users_teams DROP CONSTRAINT users_teams_user_id_fkey;
|
||||
ALTER TABLE users_teams ADD CONSTRAINT users_teams_user_id_fkey
|
||||
FOREIGN KEY (user_id) REFERENCES users(id);
|
||||
10
db/migrations/embed.go
Normal file
10
db/migrations/embed.go
Normal file
@ -0,0 +1,10 @@
|
||||
// Package migrations embeds the SQL migration files so that external modules
|
||||
// (such as the enterprise edition) can access them programmatically.
|
||||
package migrations
|
||||
|
||||
import "embed"
|
||||
|
||||
// FS contains all SQL migration files.
|
||||
//
|
||||
//go:embed *.sql
|
||||
var FS embed.FS
|
||||
Reference in New Issue
Block a user