1+ /*
2+ * Copyright (c) 2024. Devtron Inc.
3+ */
4+
5+ -- Create new cost_module_enabled column in cluster table
6+ ALTER TABLE " public" ." cluster" ADD COLUMN IF NOT EXISTS " cost_module_enabled" bool NOT NULL DEFAULT false;
7+
8+ -- Create sequence for cost_custom_view
9+ CREATE SEQUENCE IF NOT EXISTS id_seq_cost_custom_view;
10+
11+ -- Create cost_custom_view table
12+ CREATE TABLE IF NOT EXISTS " public" ." cost_custom_view" (
13+ " id" int4 NOT NULL DEFAULT nextval(' id_seq_cost_custom_view' ::regclass),
14+ " name" varchar (255 ) NOT NULL ,
15+ " identifier" varchar (255 ) NOT NULL ,
16+ " description" text ,
17+ " filters" text NOT NULL ,
18+ " active" bool NOT NULL DEFAULT true,
19+ " cluster_id" int4 NOT NULL ,
20+ " created_on" timestamptz DEFAULT NOW(),
21+ " created_by" int4,
22+ " updated_on" timestamptz ,
23+ " updated_by" int4,
24+ PRIMARY KEY (" id" )
25+ );
26+
27+ -- Indexes for cost_custom_view
28+ CREATE INDEX IF NOT EXISTS idx_cost_custom_view_name ON " public" ." cost_custom_view" (" name" ) WHERE " active" = true;
29+
30+ -- Unique constraints to ensure name uniqueness within cluster and identifier uniqueness globally
31+ CREATE UNIQUE INDEX IF NOT EXISTS idx_cost_custom_view_name_cluster_unique
32+ ON " public" ." cost_custom_view" (" name" , " cluster_id" )
33+ WHERE " active" = true;
34+
35+ CREATE UNIQUE INDEX IF NOT EXISTS idx_cost_custom_view_identifier_unique
36+ ON " public" ." cost_custom_view" (" identifier" )
37+ WHERE " active" = true;
38+
39+ -- Add comments for documentation
40+ COMMENT ON TABLE "public"."cost_custom_view" IS ' User-defined custom views for cost analysis and filtering' ;
41+ COMMENT ON COLUMN "public"."cost_custom_view"."filters" IS ' JSON string containing filter criteria for the custom view' ;
42+
43+ INSERT INTO " public" ." chart_repo" ( " name" , " url" , " is_default" , " active" , " created_on" , " created_by" , " updated_on" , " updated_by" , " external" ," auth_mode" ," deleted" ," allow_insecure_connection" )
44+ SELECT ' opencost' , ' https://opencost.github.io/opencost-helm-chart' , ' f' , ' t' , now(), 1 , now(), 1 , ' t' ,' ANONYMOUS' ,' f' ,' t'
45+ WHERE NOT EXISTS (
46+ SELECT 1 FROM " public" ." chart_repo" WHERE " name" = ' opencost' and " active" = true and " deleted" = false
47+ );
0 commit comments