Files
hfb_sys/backend/migrations/000106_cs_manual_entry_tenant_scope.sql
T

36 lines
1.4 KiB
SQL

-- +goose Up
ALTER TABLE cs_manual_entries
ADD COLUMN tenant_id BIGINT UNSIGNED NOT NULL DEFAULT 0 AFTER id,
DROP KEY uk_cs_manual_entries_entry_no_group,
ADD UNIQUE KEY uk_cs_manual_entries_tenant_entry_group (tenant_id, entry_no, entry_group),
ADD KEY idx_cs_manual_entries_tenant_admin_created (tenant_id, admin_id, created_at);
UPDATE cs_manual_entries
SET tenant_id = (SELECT id FROM tenants WHERE code = 'dachui' LIMIT 1)
WHERE tenant_id = 0;
ALTER TABLE cs_manual_entry_options
ADD COLUMN tenant_id BIGINT UNSIGNED NOT NULL DEFAULT 0 AFTER id,
DROP KEY uk_cs_manual_entry_options_type_name,
ADD UNIQUE KEY uk_cs_manual_entry_options_tenant_type_name (tenant_id, type, name),
ADD KEY idx_cs_manual_entry_options_tenant_type_sort (tenant_id, type, sort_order, id);
UPDATE cs_manual_entry_options
SET tenant_id = (SELECT id FROM tenants WHERE code = 'dachui' LIMIT 1)
WHERE tenant_id = 0;
-- +goose Down
ALTER TABLE cs_manual_entry_options
DROP KEY idx_cs_manual_entry_options_tenant_type_sort,
DROP KEY uk_cs_manual_entry_options_tenant_type_name,
ADD UNIQUE KEY uk_cs_manual_entry_options_type_name (type, name),
DROP COLUMN tenant_id;
ALTER TABLE cs_manual_entries
DROP KEY idx_cs_manual_entries_tenant_admin_created,
DROP KEY uk_cs_manual_entries_tenant_entry_group,
ADD UNIQUE KEY uk_cs_manual_entries_entry_no_group (entry_no, entry_group),
DROP COLUMN tenant_id;