1+ CREATE TABLE "webServerSettings " (
2+ " id" text PRIMARY KEY NOT NULL ,
3+ " serverIp" text ,
4+ " certificateType" " certificateType" DEFAULT ' none' NOT NULL ,
5+ " https" boolean DEFAULT false NOT NULL ,
6+ " host" text ,
7+ " letsEncryptEmail" text ,
8+ " sshPrivateKey" text ,
9+ " enableDockerCleanup" boolean DEFAULT true NOT NULL ,
10+ " logCleanupCron" text DEFAULT ' 0 0 * * *' ,
11+ " metricsConfig" jsonb DEFAULT ' {"server":{"type":"Dokploy","refreshRate":60,"port":4500,"token":"","retentionDays":2,"cronJob":"","urlCallback":"","thresholds":{"cpu":0,"memory":0}},"containers":{"refreshRate":60,"services":{"include":[],"exclude":[]}}}' ::jsonb NOT NULL ,
12+ " cleanupCacheApplications" boolean DEFAULT false NOT NULL ,
13+ " cleanupCacheOnPreviews" boolean DEFAULT false NOT NULL ,
14+ " cleanupCacheOnCompose" boolean DEFAULT false NOT NULL ,
15+ " created_at" timestamp DEFAULT now(),
16+ " updated_at" timestamp DEFAULT now() NOT NULL
17+ );
18+
19+ -- Migrate data from user table to webServerSettings
20+ -- Get the owner user's data and insert into webServerSettings
21+ INSERT INTO " webServerSettings" (
22+ " id" ,
23+ " serverIp" ,
24+ " certificateType" ,
25+ " https" ,
26+ " host" ,
27+ " letsEncryptEmail" ,
28+ " sshPrivateKey" ,
29+ " enableDockerCleanup" ,
30+ " logCleanupCron" ,
31+ " metricsConfig" ,
32+ " cleanupCacheApplications" ,
33+ " cleanupCacheOnPreviews" ,
34+ " cleanupCacheOnCompose" ,
35+ " created_at" ,
36+ " updated_at"
37+ )
38+ SELECT
39+ gen_random_uuid()::text as " id" ,
40+ u." serverIp" ,
41+ COALESCE(u." certificateType" , ' none' ) as " certificateType" ,
42+ COALESCE(u." https" , false) as " https" ,
43+ u." host" ,
44+ u." letsEncryptEmail" ,
45+ u." sshPrivateKey" ,
46+ COALESCE(u." enableDockerCleanup" , true) as " enableDockerCleanup" ,
47+ COALESCE(u." logCleanupCron" , ' 0 0 * * *' ) as " logCleanupCron" ,
48+ COALESCE(
49+ u." metricsConfig" ,
50+ ' {"server":{"type":"Dokploy","refreshRate":60,"port":4500,"token":"","retentionDays":2,"cronJob":"","urlCallback":"","thresholds":{"cpu":0,"memory":0}},"containers":{"refreshRate":60,"services":{"include":[],"exclude":[]}}}' ::jsonb
51+ ) as " metricsConfig" ,
52+ COALESCE(u." cleanupCacheApplications" , false) as " cleanupCacheApplications" ,
53+ COALESCE(u." cleanupCacheOnPreviews" , false) as " cleanupCacheOnPreviews" ,
54+ COALESCE(u." cleanupCacheOnCompose" , false) as " cleanupCacheOnCompose" ,
55+ NOW() as " created_at" ,
56+ NOW() as " updated_at"
57+ FROM " user" u
58+ INNER JOIN " member" m ON u." id" = m." user_id"
59+ WHERE m." role" = ' owner'
60+ ORDER BY m." created_at" ASC
61+ LIMIT 1 ;
62+
63+ -- If no owner found, create a default entry
64+ INSERT INTO " webServerSettings" (
65+ " id" ,
66+ " serverIp" ,
67+ " certificateType" ,
68+ " https" ,
69+ " host" ,
70+ " letsEncryptEmail" ,
71+ " sshPrivateKey" ,
72+ " enableDockerCleanup" ,
73+ " logCleanupCron" ,
74+ " metricsConfig" ,
75+ " cleanupCacheApplications" ,
76+ " cleanupCacheOnPreviews" ,
77+ " cleanupCacheOnCompose" ,
78+ " created_at" ,
79+ " updated_at"
80+ )
81+ SELECT
82+ gen_random_uuid()::text as " id" ,
83+ NULL as " serverIp" ,
84+ ' none' as " certificateType" ,
85+ false as " https" ,
86+ NULL as " host" ,
87+ NULL as " letsEncryptEmail" ,
88+ NULL as " sshPrivateKey" ,
89+ true as " enableDockerCleanup" ,
90+ ' 0 0 * * *' as " logCleanupCron" ,
91+ ' {"server":{"type":"Dokploy","refreshRate":60,"port":4500,"token":"","retentionDays":2,"cronJob":"","urlCallback":"","thresholds":{"cpu":0,"memory":0}},"containers":{"refreshRate":60,"services":{"include":[],"exclude":[]}}}' ::jsonb as " metricsConfig" ,
92+ false as " cleanupCacheApplications" ,
93+ false as " cleanupCacheOnPreviews" ,
94+ false as " cleanupCacheOnCompose" ,
95+ NOW() as " created_at" ,
96+ NOW() as " updated_at"
97+ WHERE NOT EXISTS (
98+ SELECT 1 FROM " webServerSettings"
99+ );
100+
101+
102+ -- > statement-breakpoint
103+ ALTER TABLE " user" DROP COLUMN " serverIp" ;-- > statement-breakpoint
104+ ALTER TABLE " user" DROP COLUMN " certificateType" ;-- > statement-breakpoint
105+ ALTER TABLE " user" DROP COLUMN " https" ;-- > statement-breakpoint
106+ ALTER TABLE " user" DROP COLUMN " host" ;-- > statement-breakpoint
107+ ALTER TABLE " user" DROP COLUMN " letsEncryptEmail" ;-- > statement-breakpoint
108+ ALTER TABLE " user" DROP COLUMN " sshPrivateKey" ;-- > statement-breakpoint
109+ ALTER TABLE " user" DROP COLUMN " enableDockerCleanup" ;-- > statement-breakpoint
110+ ALTER TABLE " user" DROP COLUMN " logCleanupCron" ;-- > statement-breakpoint
111+ ALTER TABLE " user" DROP COLUMN " metricsConfig" ;-- > statement-breakpoint
112+ ALTER TABLE " user" DROP COLUMN " cleanupCacheApplications" ;-- > statement-breakpoint
113+ ALTER TABLE " user" DROP COLUMN " cleanupCacheOnPreviews" ;-- > statement-breakpoint
114+ ALTER TABLE " user" DROP COLUMN " cleanupCacheOnCompose" ;
0 commit comments