Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions internal/database/default_data_seed.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,11 +232,12 @@ func seedDefaultData(w seedWriter) error {
}
}

// 11. Item types.
// 11. Item types. Membership is recorded only in configuration_set_item_types
// (step 12); the deprecated item_types.configuration_set_id scalar is gone.
for _, itemType := range defaultItemTypes {
if _, err := w.Exec(
"INSERT INTO item_types (builtin_key, configuration_set_id, name, description, icon, color, hierarchy_level, sort_order, is_default) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)",
itemType.builtinKey, configSetID, itemType.name, itemType.description, itemType.icon, itemType.color, itemType.hierarchyLevel, itemType.sortOrder, true,
"INSERT INTO item_types (builtin_key, name, description, icon, color, hierarchy_level, sort_order, is_default) VALUES (?, ?, ?, ?, ?, ?, ?, ?)",
itemType.builtinKey, itemType.name, itemType.description, itemType.icon, itemType.color, itemType.hierarchyLevel, itemType.sortOrder, true,
); err != nil {
return fmt.Errorf("failed to create default item type %s: %w", itemType.name, err)
}
Expand Down
442 changes: 441 additions & 1 deletion internal/database/migrations.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion internal/database/schema/agents.sql
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ CREATE TABLE IF NOT EXISTS workspace_agent_bindings (
target_pool_id INTEGER, -- soft ref to action_capabilities (runner_pool); NULL = local in-process run (WI-195)
instructions TEXT NOT NULL DEFAULT '', -- appended to the run's initial prompt as the agent's role/persona (WI-258)
runner_image TEXT, -- custom coding-agent container image for remote (pool) runs; NULL = the runner's default windshift-agent image (WI-450)
created_by_user_id INTEGER NOT NULL,
created_by_user_id INTEGER, -- soft audit ref; NULL once the creator is deleted
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (workspace_id) REFERENCES workspaces(id) ON DELETE CASCADE,
Expand Down
163 changes: 11 additions & 152 deletions internal/database/schema/base_tables_postgres.sql
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,7 @@ CREATE TABLE IF NOT EXISTS priorities (
CREATE TABLE IF NOT EXISTS item_types (
id SERIAL PRIMARY KEY,
builtin_key TEXT,
configuration_set_id INTEGER, -- Made nullable for many-to-many relationship
name TEXT NOT NULL UNIQUE, -- Changed to global unique (not per config set)
name TEXT NOT NULL UNIQUE, -- Global unique; set membership lives in configuration_set_item_types
description TEXT,
is_default BOOLEAN DEFAULT false,
icon TEXT DEFAULT 'FileText',
Expand Down Expand Up @@ -265,117 +264,23 @@ CREATE TABLE IF NOT EXISTS status_categories (
updated_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP
);

-- From milestones_postgres.sql
CREATE TABLE IF NOT EXISTS milestone_categories (
id SERIAL PRIMARY KEY,
name TEXT NOT NULL UNIQUE,
color TEXT NOT NULL, -- Hex color code (e.g., "#3b82f6")
description TEXT,
created_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP
);

-- From permissions_postgres.sql
CREATE TABLE IF NOT EXISTS permissions (
id SERIAL PRIMARY KEY,
permission_key TEXT UNIQUE NOT NULL,
permission_name TEXT NOT NULL,
description TEXT,
scope TEXT NOT NULL CHECK (scope IN ('global', 'workspace')),
is_system BOOLEAN DEFAULT false,
created_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP
);
-- Tables owned by a domain schema file are created there, not here. A
-- duplicate CREATE TABLE IF NOT EXISTS in this file would win the bootstrap
-- race (this file runs first) and silently discard the owner's foreign keys,
-- constraints and column shape. Keep base_tables limited to tables with no
-- foreign-key dependencies.

-- workspace_roles is fully defined in permissions_postgres.sql (which runs
-- after this file). The previous duplicate definition here was missing the
-- permissions_enabled column, and CREATE TABLE IF NOT EXISTS would silently
-- skip the proper definition once base_tables had already created the stub.

-- From system_postgres.sql
CREATE TABLE IF NOT EXISTS system_settings (
id SERIAL PRIMARY KEY,
key TEXT NOT NULL UNIQUE,
value TEXT,
value_type TEXT DEFAULT 'string', -- string, boolean, integer, json
description TEXT,
category TEXT DEFAULT 'general',
created_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP
);

CREATE INDEX IF NOT EXISTS idx_system_settings_category ON system_settings(category);

CREATE TABLE IF NOT EXISTS themes (
id SERIAL PRIMARY KEY,
builtin_key TEXT,
name TEXT NOT NULL,
description TEXT,
is_default BOOLEAN DEFAULT false,
is_active BOOLEAN DEFAULT false,
nav_background_color_light TEXT NOT NULL DEFAULT '#ffffff',
nav_text_color_light TEXT NOT NULL DEFAULT '#374151',
nav_background_color_dark TEXT NOT NULL DEFAULT '#1f2937',
nav_text_color_dark TEXT NOT NULL DEFAULT '#f3f4f6',
logo_url TEXT,
logo_url_dark TEXT,
logo_full_url TEXT,
logo_full_url_dark TEXT,
brand_layout TEXT NOT NULL DEFAULT 'mark_text',
created_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP
);

CREATE UNIQUE INDEX IF NOT EXISTS uq_themes_builtin_key ON themes(builtin_key) WHERE builtin_key IS NOT NULL;

CREATE TABLE IF NOT EXISTS board_configurations (
id SERIAL PRIMARY KEY,
workspace_id INTEGER,
collection_id INTEGER,
backlog_status_ids JSONB,
list_columns JSONB,
roadmap_config JSONB,
card_fields JSONB,
view_settings JSONB,
show_rightmost_column_last_50 BOOLEAN DEFAULT false,
completed_item_retention_days INTEGER,
created_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP
);

-- From content_postgres.sql
CREATE TABLE IF NOT EXISTS attachment_settings (
id SERIAL PRIMARY KEY,
max_file_size INTEGER NOT NULL DEFAULT 52428800, -- 50MB default
allowed_mime_types TEXT, -- JSON array of allowed MIME types
attachment_path TEXT NOT NULL,
enabled BOOLEAN DEFAULT true,
created_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP
);

CREATE TABLE IF NOT EXISTS link_types (
id SERIAL PRIMARY KEY,
builtin_key TEXT,
name TEXT NOT NULL UNIQUE,
description TEXT,
forward_label TEXT NOT NULL,
reverse_label TEXT NOT NULL,
color TEXT DEFAULT '#6b7280',
is_system BOOLEAN DEFAULT false,
active BOOLEAN DEFAULT true,
allowed_entity_types TEXT DEFAULT NULL,
created_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP
);

CREATE UNIQUE INDEX IF NOT EXISTS uq_link_types_builtin_key ON link_types(builtin_key) WHERE builtin_key IS NOT NULL;

-- Email templates: per-sender HTML/text/subject Go templates editable from the
-- admin UI. `name` is the lookup key consumed by senders (e.g. "magic_link",
-- "notification_batch"). The legacy template_type/event_type/template_body/
-- template_variables/channel_type columns are kept for backwards compatibility
-- but are no longer read or written by application code.
-- "notification_batch"). template_type still selects rows for the notification
-- cache refresh, so it is not dead. The remaining legacy columns (event_type,
-- template_subject, template_body, template_variables, channel_type) are unread
-- but retained pending a deliberate audit of existing template rows.
CREATE TABLE IF NOT EXISTS notification_templates (
id SERIAL PRIMARY KEY,
name TEXT NOT NULL UNIQUE,
Expand All @@ -386,7 +291,7 @@ CREATE TABLE IF NOT EXISTS notification_templates (
is_system BOOLEAN DEFAULT false,
is_active BOOLEAN DEFAULT true,
is_customized BOOLEAN NOT NULL DEFAULT false, -- true once an admin saves an edit; unmodified seeds fall back to the localized built-in default
template_type TEXT, -- legacy, unused
template_type TEXT, -- read by the notification cache refresh
event_type TEXT, -- legacy, unused
template_subject TEXT, -- legacy, unused
template_body TEXT, -- legacy, unused
Expand All @@ -412,52 +317,6 @@ CREATE TABLE IF NOT EXISTS notification_template_translations (
FOREIGN KEY (template_id) REFERENCES notification_templates(id) ON DELETE CASCADE
);

-- From tests_postgres.sql (simplified for base tables - full definition with FKs in tests_postgres.sql)
CREATE TABLE IF NOT EXISTS test_folders (
id SERIAL PRIMARY KEY,
workspace_id INTEGER NOT NULL,
parent_id INTEGER REFERENCES test_folders(id) ON DELETE SET NULL,
name TEXT NOT NULL,
description TEXT,
sort_order INTEGER DEFAULT 0,
created_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP
);

CREATE INDEX IF NOT EXISTS idx_test_folders_parent_id ON test_folders(parent_id);

CREATE TABLE IF NOT EXISTS test_labels (
id SERIAL PRIMARY KEY,
workspace_id INTEGER NOT NULL,
name TEXT NOT NULL,
color TEXT NOT NULL DEFAULT '#3B82F6',
description TEXT DEFAULT '',
created_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP,
UNIQUE(workspace_id, name)
);

-- From iterations_postgres.sql
CREATE TABLE IF NOT EXISTS iteration_types (
id SERIAL PRIMARY KEY,
name TEXT NOT NULL UNIQUE,
color TEXT DEFAULT '#6b7280',
duration_days INTEGER NOT NULL DEFAULT 14,
description TEXT,
created_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP
);

-- From portal_postgres.sql
CREATE TABLE IF NOT EXISTS contact_roles (
id SERIAL PRIMARY KEY,
name TEXT NOT NULL UNIQUE,
description TEXT,
is_system BOOLEAN DEFAULT false,
sort_order INTEGER NOT NULL DEFAULT 0,
created_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP
);

-- ============================================
-- INDEXES
-- ============================================
Expand Down
4 changes: 1 addition & 3 deletions internal/database/schema/config_workflows.sql
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ CREATE TABLE IF NOT EXISTS configuration_sets (
CREATE TABLE IF NOT EXISTS item_types (
id INTEGER PRIMARY KEY AUTOINCREMENT,
builtin_key TEXT,
configuration_set_id INTEGER, -- Made nullable for many-to-many relationship
name TEXT NOT NULL UNIQUE, -- Changed to global unique (not per config set)
name TEXT NOT NULL UNIQUE, -- Global unique; set membership lives in configuration_set_item_types
description TEXT,
is_default BOOLEAN DEFAULT false,
icon TEXT DEFAULT 'FileText',
Expand Down Expand Up @@ -127,7 +126,6 @@ CREATE TABLE IF NOT EXISTS screen_system_fields (
);

CREATE INDEX IF NOT EXISTS idx_configuration_sets_workflow_id ON configuration_sets(workflow_id);
CREATE INDEX IF NOT EXISTS idx_item_types_configuration_set_id ON item_types(configuration_set_id);
CREATE INDEX IF NOT EXISTS idx_item_types_hierarchy_level ON item_types(hierarchy_level);
CREATE INDEX IF NOT EXISTS idx_item_types_sort_order ON item_types(sort_order);
CREATE INDEX IF NOT EXISTS idx_screen_fields_screen_id ON screen_fields(screen_id);
Expand Down
1 change: 0 additions & 1 deletion internal/database/schema/config_workflows_postgres.sql
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ CREATE UNIQUE INDEX IF NOT EXISTS uq_statuses_builtin_key ON statuses(builtin_ke
CREATE UNIQUE INDEX IF NOT EXISTS uq_workflows_builtin_key ON workflows(builtin_key) WHERE builtin_key IS NOT NULL;

-- Item type indexes (moved to base_tables_postgres.sql)
CREATE INDEX IF NOT EXISTS idx_item_types_configuration_set_id ON item_types(configuration_set_id);

-- Screen field indexes
CREATE INDEX IF NOT EXISTS idx_screen_fields_screen_id ON screen_fields(screen_id);
Expand Down
8 changes: 7 additions & 1 deletion internal/database/schema/integrations.sql
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,10 @@ CREATE TABLE IF NOT EXISTS zammad_connections (
correlation_field TEXT NOT NULL DEFAULT 'windshift_item_key',
closed_state_ids TEXT NOT NULL DEFAULT '[]',
completion_status_id INTEGER,
-- Legacy connection-level scope. Runtime queries use action_credentials and
-- action_credential_workspaces; migration 20260901_zammad_canonical_workspace_scope
-- reads this state to backfill managed credentials. Retire only after every
-- supported upgrade has run that backfill (WI-2366).
-- migration: 20260829_zammad_integration
applies_to_all_workspaces BOOLEAN NOT NULL DEFAULT false,
last_tested_at DATETIME,
Expand All @@ -179,7 +183,9 @@ CREATE TABLE IF NOT EXISTS zammad_connections (

CREATE INDEX IF NOT EXISTS idx_zammad_connections_credential ON zammad_connections(credential_id);

-- Workspace membership scope for connection-scoped credentials.
-- Legacy workspace membership for connection-scoped credentials. Superseded by
-- action_credential_workspaces; retained only for the 20260901 backfill. Retire
-- once every supported upgrade has run it (WI-2366).
-- migration: 20260829_zammad_integration
CREATE TABLE IF NOT EXISTS zammad_connection_workspaces (
provider_id TEXT NOT NULL,
Expand Down
8 changes: 7 additions & 1 deletion internal/database/schema/integrations_postgres.sql
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@ CREATE TABLE IF NOT EXISTS zammad_connections (
correlation_field TEXT NOT NULL DEFAULT 'windshift_item_key',
closed_state_ids TEXT NOT NULL DEFAULT '[]',
completion_status_id INTEGER REFERENCES statuses(id) ON DELETE SET NULL,
-- Legacy connection-level scope. Runtime queries use action_credentials and
-- action_credential_workspaces; migration 20260901_zammad_canonical_workspace_scope
-- reads this state to backfill managed credentials. Retire only after every
-- supported upgrade has run that backfill (WI-2366).
-- migration: 20260829_zammad_integration
applies_to_all_workspaces BOOLEAN NOT NULL DEFAULT false,
last_tested_at TIMESTAMPTZ,
Expand All @@ -157,7 +161,9 @@ CREATE TABLE IF NOT EXISTS zammad_connections (

CREATE INDEX IF NOT EXISTS idx_zammad_connections_credential ON zammad_connections(credential_id);

-- Workspace membership scope for connection-scoped credentials.
-- Legacy workspace membership for connection-scoped credentials. Superseded by
-- action_credential_workspaces; retained only for the 20260901 backfill. Retire
-- once every supported upgrade has run it (WI-2366).
-- migration: 20260829_zammad_integration
CREATE TABLE IF NOT EXISTS zammad_connection_workspaces (
provider_id TEXT NOT NULL REFERENCES zammad_connections(provider_id) ON DELETE CASCADE,
Expand Down
9 changes: 4 additions & 5 deletions internal/database/schema/items.sql
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,10 @@ CREATE TABLE IF NOT EXISTS items (
FOREIGN KEY (item_type_id) REFERENCES item_types(id) ON DELETE SET NULL,
FOREIGN KEY (parent_id) REFERENCES items(id) ON DELETE CASCADE,
FOREIGN KEY (iteration_id) REFERENCES iterations(id) ON DELETE SET NULL,
FOREIGN KEY (time_project_id) REFERENCES time_projects(id) ON DELETE SET NULL,
FOREIGN KEY (assignee_id) REFERENCES users(id) ON DELETE SET NULL,
FOREIGN KEY (creator_id) REFERENCES users(id) ON DELETE SET NULL,
FOREIGN KEY (reporter_id) REFERENCES users(id) ON DELETE SET NULL,
FOREIGN KEY (creator_portal_customer_id) REFERENCES portal_customers(id) ON DELETE SET NULL,
-- time_project_id, assignee_id, creator_id, reporter_id and
-- creator_portal_customer_id declare their foreign key inline above.
-- Existing SQLite installs keep the duplicate copies until the planned items
-- rebuild; fresh installs declare each relationship once.
UNIQUE(workspace_id, workspace_item_number)
);

Expand Down
3 changes: 1 addition & 2 deletions internal/database/schema/milestones.sql
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,7 @@ CREATE UNIQUE INDEX IF NOT EXISTS uq_milestones_workspace_external_key
WHERE external_key IS NOT NULL;

-- Composite index supports the per-scope position ordering used by drag-and-drop
-- reorder. Existing installs use milestones_existing.sql before catalog
-- migrations, so this canonical fresh-install schema can include the index.
-- reorder.
CREATE INDEX IF NOT EXISTS idx_milestones_position ON milestones(is_global, workspace_id, category_id, position);

-- migration: 20260716_milestone_scope_guard
Loading
Loading