diff --git a/db/click_house/migrate/main/20240115122100_drop_audit_events.rb b/db/click_house/migrate/main/20240115122100_drop_audit_events.rb new file mode 100644 index 0000000000000000000000000000000000000000..198e83ff7eec5503f91fea00a35d532d7fb0a821 --- /dev/null +++ b/db/click_house/migrate/main/20240115122100_drop_audit_events.rb @@ -0,0 +1,37 @@ +# frozen_string_literal: true + +class DropAuditEvents < ClickHouse::Migration + def up + execute <<~SQL + DROP TABLE IF EXISTS audit_events; + SQL + end + + def down + execute <<~SQL + CREATE TABLE IF NOT EXISTS audit_events + ( + id UInt64 DEFAULT 0, + author_id UInt64 DEFAULT 0, + author_name String DEFAULT '', + created_at DateTime64(6, 'UTC') DEFAULT now(), + details String DEFAULT '', + entity_id UInt64 DEFAULT 0, + entity_path String DEFAULT '', + entity_type LowCardinality(String) DEFAULT '', + ip_address String DEFAULT '', + target_details String DEFAULT '', + target_id UInt64 DEFAULT 0, + target_type LowCardinality(String) DEFAULT '', + is_deleted UInt8 DEFAULT 0, + ) ENGINE = ReplacingMergeTree(created_at, is_deleted) + PARTITION BY toYear(created_at) + ORDER BY (entity_type, entity_id, author_id, created_at, id); + SQL + + execute <<~SQL + ALTER TABLE audit_events + ADD PROJECTION IF NOT EXISTS by_id (SELECT * ORDER BY id); + SQL + end +end diff --git a/db/click_house/migrate/main/20240115162101_recreate_audit_events.rb b/db/click_house/migrate/main/20240115162101_recreate_audit_events.rb new file mode 100644 index 0000000000000000000000000000000000000000..0fcef508c4f2bcf2fb1167622412142eee95540e --- /dev/null +++ b/db/click_house/migrate/main/20240115162101_recreate_audit_events.rb @@ -0,0 +1,37 @@ +# frozen_string_literal: true + +class RecreateAuditEvents < ClickHouse::Migration + def up + execute <<~SQL + CREATE TABLE IF NOT EXISTS audit_events + ( + id UInt64 DEFAULT 0, + author_id Int64 DEFAULT 0, + author_name String DEFAULT '', + created_at DateTime64(6, 'UTC') DEFAULT now(), + details String DEFAULT '', + entity_id Int64 DEFAULT 0, + entity_path String DEFAULT '', + entity_type LowCardinality(String) DEFAULT '', + ip_address String DEFAULT '', + target_details String DEFAULT '', + target_id Int64 DEFAULT 0, + target_type LowCardinality(String) DEFAULT '', + is_deleted UInt8 DEFAULT 0, + ) ENGINE = ReplacingMergeTree(created_at, is_deleted) + PARTITION BY toYear(created_at) + ORDER BY (entity_type, entity_id, author_id, created_at, id); + SQL + + execute <<~SQL + ALTER TABLE audit_events + ADD PROJECTION IF NOT EXISTS by_id (SELECT * ORDER BY id); + SQL + end + + def down + execute <<~SQL + DROP TABLE audit_events + SQL + end +end