gokuNodeInfo.go 1.8 KB
Newer Older
Y
Your Name 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
package goku311

import (
	SQL "database/sql"
)

const gokuNodeInfoSQL = `DROP TABLE  IF EXISTS goku_node_info_new;
CREATE TABLE "goku_node_info_new" (
  "nodeID" integer NOT NULL PRIMARY KEY AUTOINCREMENT,
  "createTime" text,
  "updateTime" text,
  "groupID" integer(11) NOT NULL DEFAULT 0,
  "nodeName" text(255) NOT NULL,
  "nodeStatus" integer(11) NOT NULL,
  "version" text(255),
  "sshAddress" text(255) DEFAULT 22,
  "sshUserName" text(255),
  "sshPassword" text(255),
  "gatewayPath" text(255),
  "sshKey" text,
  "authMethod" integer(4) NOT NULL DEFAULT 0,
  "clusterID" integer(11) NOT NULL DEFAULT 0,
  "listenAddress" text(22) NOT NULL DEFAULT '',
  "adminAddress" text(22) NOT NULL DEFAULT '',
  "nodeKey" TEXT(32) NOT NULL DEFAULT ''
);

CREATE UNIQUE INDEX "nodeKey_new" 
ON "goku_node_info_new" (
  "nodeKey" ASC
);`

func createGokuNodeInfo(db *SQL.DB) error {
	_, err := db.Exec(gokuNodeInfoSQL)
	if err != nil {
		return err
	}

	sql := "INSERT INTO goku_node_info_new (`nodeID`,`createTime`,`updateTime`,`groupID`,`nodeName`,`nodeStatus`,`version`,`sshAddress`,`sshUserName`,`sshPassword`,`gatewayPath`,`sshKey`,`authMethod`,`clusterID`,`listenAddress`,`adminAddress`,`nodeKey`) SELECT `nodeID`,`createTime`,`updateTime`,`groupID`,`nodeName`,`nodeStatus`,`version`,`sshPort`,`userName`,`password`,`gatewayPath`,`key`,`authMethod`,`clusterID`,`nodeIP` || ':' || `nodePort`,`nodeIP` || ':' || `nodePort`,`nodeID` || `nodeIP` || ':' || `nodePort` FROM goku_node_info;"
	_, err = db.Exec(sql)
	if err != nil {
		return err
	}
	_, err = db.Exec("DROP TABLE IF EXISTS goku_node_info")
	if err != nil {
		return err
	}
	_, err = db.Exec("ALTER TABLE goku_node_info_new RENAME TO goku_node_info")
	if err != nil {
		return err
	}
	_, err = db.Exec("DROP TABLE  IF EXISTS goku_node_info_new")
	if err != nil {
		return err
	}

	return nil
}