52 lines
2.0 KiB
SQL
52 lines
2.0 KiB
SQL
CREATE TABLE IF NOT EXISTS automation_rules (
|
|
id BIGSERIAL PRIMARY KEY,
|
|
created_at TIMESTAMPTZ,
|
|
updated_at TIMESTAMPTZ,
|
|
deleted_at TIMESTAMPTZ,
|
|
account_id BIGINT NOT NULL,
|
|
event_name VARCHAR(100) NOT NULL,
|
|
name VARCHAR(255) NOT NULL,
|
|
description TEXT,
|
|
active BOOLEAN DEFAULT true,
|
|
active_at TIMESTAMPTZ,
|
|
inactive_at TIMESTAMPTZ,
|
|
conditions JSONB DEFAULT '[]'::jsonb,
|
|
actions JSONB DEFAULT '[]'::jsonb
|
|
);
|
|
|
|
CREATE INDEX IF NOT EXISTS idx_automation_rules_account_id ON automation_rules (account_id);
|
|
CREATE INDEX IF NOT EXISTS idx_automation_rules_event_name ON automation_rules (event_name);
|
|
CREATE INDEX IF NOT EXISTS idx_automation_rules_active_at ON automation_rules (active_at);
|
|
CREATE INDEX IF NOT EXISTS idx_automation_rules_inactive_at ON automation_rules (inactive_at);
|
|
CREATE INDEX IF NOT EXISTS idx_automation_rules_deleted_at ON automation_rules (deleted_at);
|
|
|
|
CREATE TABLE IF NOT EXISTS macros (
|
|
id BIGSERIAL PRIMARY KEY,
|
|
created_at TIMESTAMPTZ,
|
|
updated_at TIMESTAMPTZ,
|
|
deleted_at TIMESTAMPTZ,
|
|
account_id BIGINT NOT NULL,
|
|
name VARCHAR(255) NOT NULL,
|
|
actions JSONB DEFAULT '[]'::jsonb,
|
|
visibility INTEGER DEFAULT 0,
|
|
active BOOLEAN NOT NULL DEFAULT true,
|
|
created_by_id BIGINT NOT NULL,
|
|
updated_by_id BIGINT NOT NULL
|
|
);
|
|
|
|
CREATE INDEX IF NOT EXISTS idx_macros_account_id ON macros (account_id);
|
|
CREATE INDEX IF NOT EXISTS idx_macros_created_by_id ON macros (created_by_id);
|
|
CREATE INDEX IF NOT EXISTS idx_macros_updated_by_id ON macros (updated_by_id);
|
|
CREATE INDEX IF NOT EXISTS idx_macros_deleted_at ON macros (deleted_at);
|
|
|
|
CREATE TABLE IF NOT EXISTS macro_executions (
|
|
id BIGSERIAL PRIMARY KEY,
|
|
macro_id BIGINT NOT NULL,
|
|
conversation_id BIGINT NOT NULL,
|
|
executed_by_id BIGINT NOT NULL
|
|
);
|
|
|
|
CREATE INDEX IF NOT EXISTS idx_macro_executions_macro_id ON macro_executions (macro_id);
|
|
CREATE INDEX IF NOT EXISTS idx_macro_executions_conversation_id ON macro_executions (conversation_id);
|
|
CREATE INDEX IF NOT EXISTS idx_macro_executions_executed_by_id ON macro_executions (executed_by_id);
|