@@ -103,52 +103,69 @@ type Cluster struct {
103103 Topology string
104104 Pool string
105105 Current bool
106+ Type string
106107}
107108
108109var (
109110 // table: clusters
110111 CreateClustersTable = `
111- CREATE TABLE IF NOT EXISTS clusters (
112+ CREATE TABLE IF NOT EXISTS clusters_new (
112113 id INTEGER PRIMARY KEY AUTOINCREMENT,
113114 uuid TEXT NOT NULL,
114115 name TEXT NOT NULL UNIQUE,
115116 description TEXT,
116117 topology TEXT NULL,
117118 pool TEXT NULL,
118119 create_time DATE NOT NULL,
119- current INTEGER DEFAULT 0
120+ current INTEGER DEFAULT 0,
121+ type TEXT NOT NULL
120122 )
121123 `
122124
123125 // insert cluster
124126 InsertCluster = `
125- INSERT INTO clusters(uuid, name, description, topology, pool, create_time)
126- VALUES(?, ?, ?, ?, "", datetime('now','localtime'))
127+ INSERT INTO clusters_new(uuid, name, description, topology, type, pool, create_time)
128+ VALUES(?, ?, ?, ?, ?, "", datetime('now','localtime'))
129+ `
130+ // check if view exists
131+ CheckMigrationNeeded = `SELECT COUNT(*) FROM sqlite_master WHERE type='view' AND name = 'clusters'`
132+
133+ // update new cluster column
134+ AddTypeField = `ALTER TABLE clusters_new ADD COLUMN type TEXT NOT NULL DEFAULT 'develop'`
135+
136+ // rename clusters table
137+ RenameClusters = `ALTER TABLE clusters RENAME TO clusters_new`
138+
139+ // create view for old table
140+ CreateClustersView = `
141+ CREATE VIEW IF NOT EXISTS clusters AS
142+ SELECT id, uuid, name, description, topology, pool, create_time, current
143+ FROM clusters_new
127144 `
128145
129146 // delete cluster
130- DeleteCluster = `DELETE from clusters WHERE name = ?`
147+ DeleteCluster = `DELETE from clusters_new WHERE name = ?`
131148
132149 // select cluster
133- SelectCluster = `SELECT * FROM clusters WHERE name LIKE ?`
150+ SelectCluster = `SELECT * FROM clusters_new WHERE name LIKE ?`
134151
135152 // get current cluster
136- GetCurrentCluster = `SELECT * FROM clusters WHERE current = 1`
153+ GetCurrentCluster = `SELECT * FROM clusters_new WHERE current = 1`
137154
138155 // checkout cluster
139156 CheckoutCluster = `
140- UPDATE clusters
157+ UPDATE clusters_new
141158 SET current = CASE name
142159 WHEN ? THEN 1
143160 ELSE 0
144161 END
145162 `
146163
147164 // set cluster topology
148- SetClusterTopology = `UPDATE clusters SET topology = ? WHERE id = ?`
165+ SetClusterTopology = `UPDATE clusters_new SET topology = ? WHERE id = ?`
149166
150167 // set cluster pool
151- SetClusterPool = `UPDATE clusters SET topology = ?, pool = ? WHERE id = ?`
168+ SetClusterPool = `UPDATE clusters_new SET topology = ?, pool = ? WHERE id = ?`
152169)
153170
154171// service
0 commit comments