Skip to content

Commit f094abe

Browse files
authored
feat: Optimize the table creation statement (#495)
1 parent d11aa71 commit f094abe

File tree

8 files changed

+221
-199
lines changed

8 files changed

+221
-199
lines changed

Makefile

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,14 @@ build_server:
4040
@echo "Building server..."
4141
@bash $(BUILD_SERVER_SCRIPT)
4242

43-
sync_db:
43+
sync_db: env
4444
@echo "Syncing database..."
4545
@docker compose -f $(COMPOSE_FILE) --env-file $(ENV_FILE) --profile mysql-setup up -d
4646

47-
dump_db: dump_sql_schema
47+
dump_db: env dump_sql_schema
4848
@echo "Dumping database..."
49-
@bash $(DUMP_DB_SCRIPT)
49+
@. $(ENV_FILE); \
50+
bash $(DUMP_DB_SCRIPT)
5051

5152
sql_init:
5253
@echo "Init sql data..."
@@ -85,6 +86,7 @@ dump_sql_schema:
8586
@. $(ENV_FILE); \
8687
{ echo "SET NAMES utf8mb4;\nCREATE DATABASE IF NOT EXISTS opencoze COLLATE utf8mb4_unicode_ci;"; atlas schema inspect -u $$ATLAS_URL --format "{{ sql . }}" --exclude "atlas_schema_revisions,table_*" | sed 's/CREATE TABLE/CREATE TABLE IF NOT EXISTS/g'; } > $(MYSQL_SCHEMA)
8788
@sed -i.bak -E 's/(\))[[:space:]]+CHARSET utf8mb4/\1 ENGINE=InnoDB CHARSET utf8mb4/' $(MYSQL_SCHEMA) && rm -f $(MYSQL_SCHEMA).bak
89+
@sed -i.bak "s/\"/'/g" $(MYSQL_SCHEMA) && rm -f $(MYSQL_SCHEMA).bak
8890
@cat $(MYSQL_INIT_SQL) >> $(MYSQL_SCHEMA)
8991
@echo "Dumping mysql schema to helm/charts/opencoze/files/mysql ..."
9092
@cp $(MYSQL_SCHEMA) ./helm/charts/opencoze/files/mysql/
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
-- Modify "connector_workflow_version" table
2+
ALTER TABLE `opencoze`.`connector_workflow_version` COMMENT "connector workflow version", RENAME INDEX `idx_connector_id_workflow_id_version` TO `uniq_connector_id_workflow_id_version`;
3+
-- Modify "knowledge" table
4+
ALTER TABLE `opencoze`.`knowledge` MODIFY COLUMN `name` varchar(150) NOT NULL DEFAULT "" COMMENT "knowledge_s name";
5+
-- Modify "node_execution" table
6+
ALTER TABLE `opencoze`.`node_execution` MODIFY COLUMN `composite_node_index` bigint unsigned NULL COMMENT "loop or batch_s execution index", MODIFY COLUMN `parent_node_id` varchar(128) NULL COMMENT "when as inner node for loop or batch, this is the parent node_s key" COLLATE utf8mb4_unicode_ci;
7+
-- Modify "plugin_oauth_auth" table
8+
ALTER TABLE `opencoze`.`plugin_oauth_auth` MODIFY COLUMN `access_token` text NULL COMMENT "Access Token", MODIFY COLUMN `refresh_token` text NULL COMMENT "Refresh Token";
9+
-- Modify "single_agent_draft" table
10+
ALTER TABLE `opencoze`.`single_agent_draft` MODIFY COLUMN `description` text NULL COMMENT "Agent Description";
11+
-- Modify "single_agent_version" table
12+
ALTER TABLE `opencoze`.`single_agent_version` MODIFY COLUMN `description` text NULL COMMENT "Agent Description";
13+
-- Modify "workflow_draft" table
14+
ALTER TABLE `opencoze`.`workflow_draft` MODIFY COLUMN `canvas` mediumtext NULL COMMENT "Front end schema";
15+
-- Modify "workflow_snapshot" table
16+
ALTER TABLE `opencoze`.`workflow_snapshot` MODIFY COLUMN `canvas` mediumtext NULL COMMENT "frontend schema for this snapshot";
17+
-- Modify "workflow_version" table
18+
ALTER TABLE `opencoze`.`workflow_version` MODIFY COLUMN `canvas` mediumtext NULL COMMENT "Front end schema";

docker/atlas/migrations/atlas.sum

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
h1:NkRT9U8wV1wIRcHvkU2N3yjWDjvyi6avhjzgpMJdEtM=
1+
h1:3ar6fnSw3e4ni74BcE2N9cIentO27OcfSt465WTv2Po=
22
20250703095335_initial.sql h1:/joaeUTMhXqAEc0KwsSve5+bYM0qPOp+9OizJtsRc+U=
33
20250703115304_update.sql h1:cbYo6Q6Lh96hB4hu5KW2Nn/Mr0VDpg7a1WPgpIb1SOc=
44
20250704040445_update.sql h1:QWmoPY//oQ+GFZwET9w/oAWa8mM0KVaD5G8Yiu9bMqY=
@@ -7,3 +7,4 @@ h1:NkRT9U8wV1wIRcHvkU2N3yjWDjvyi6avhjzgpMJdEtM=
77
20250711034533_update.sql h1:EWeK//5urS9hJIRCeD3lwQYWNH9AIKEWG9pMLdw7KPc=
88
20250717125913_update.sql h1:WtPR99RlWZn0rXZsB19qp1hq0FwO5qmFhcTcV6EnFYs=
99
20250730131847_update.sql h1:qIutMrXtuOA98jeucTFxXck+sQNjNTtIF2apbCYt3IY=
10+
20250802115105_update.sql h1:irreQaMAL0LtXcDlkdHP86C7/0e2HzEVsa1hP/FkZ2M=

docker/atlas/opencoze_latest_schema.hcl

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,8 @@ table "app_release_record" {
507507
}
508508
}
509509
table "connector_workflow_version" {
510-
schema = schema.opencoze
510+
schema = schema.opencoze
511+
comment = "connector workflow version"
511512
column "id" {
512513
null = false
513514
type = bigint
@@ -550,7 +551,7 @@ table "connector_workflow_version" {
550551
index "idx_connector_id_workflow_id_create_at" {
551552
columns = [column.connector_id, column.workflow_id, column.created_at]
552553
}
553-
index "idx_connector_id_workflow_id_version" {
554+
index "uniq_connector_id_workflow_id_version" {
554555
unique = true
555556
columns = [column.connector_id, column.workflow_id, column.version]
556557
}
@@ -862,7 +863,7 @@ table "knowledge" {
862863
null = false
863864
type = varchar(150)
864865
default = ""
865-
comment = "knowledge's name"
866+
comment = "knowledge_s name"
866867
}
867868
column "app_id" {
868869
null = false
@@ -1647,7 +1648,7 @@ table "node_execution" {
16471648
null = true
16481649
type = bigint
16491650
unsigned = true
1650-
comment = "loop or batch's execution index"
1651+
comment = "loop or batch_s execution index"
16511652
}
16521653
column "composite_node_items" {
16531654
null = true
@@ -1658,7 +1659,7 @@ table "node_execution" {
16581659
column "parent_node_id" {
16591660
null = true
16601661
type = varchar(128)
1661-
comment = "when as inner node for loop or batch, this is the parent node's key"
1662+
comment = "when as inner node for loop or batch, this is the parent node_s key"
16621663
collate = "utf8mb4_unicode_ci"
16631664
}
16641665
column "sub_execute_id" {
@@ -2005,12 +2006,12 @@ table "plugin_oauth_auth" {
20052006
comment = "Authorization Code OAuth Config"
20062007
}
20072008
column "access_token" {
2008-
null = false
2009+
null = true
20092010
type = text
20102011
comment = "Access Token"
20112012
}
20122013
column "refresh_token" {
2013-
null = false
2014+
null = true
20142015
type = text
20152016
comment = "Refresh Token"
20162017
}
@@ -2523,7 +2524,7 @@ table "single_agent_draft" {
25232524
comment = "Agent Name"
25242525
}
25252526
column "description" {
2526-
null = false
2527+
null = true
25272528
type = text
25282529
comment = "Agent Description"
25292530
}
@@ -2751,7 +2752,7 @@ table "single_agent_version" {
27512752
comment = "Agent Name"
27522753
}
27532754
column "description" {
2754-
null = false
2755+
null = true
27552756
type = text
27562757
comment = "Agent Description"
27572758
}
@@ -3526,7 +3527,7 @@ table "workflow_draft" {
35263527
comment = "workflow ID"
35273528
}
35283529
column "canvas" {
3529-
null = false
3530+
null = true
35303531
type = mediumtext
35313532
comment = "Front end schema"
35323533
}
@@ -3948,7 +3949,7 @@ table "workflow_snapshot" {
39483949
comment = "the commit id of the workflow draft"
39493950
}
39503951
column "canvas" {
3951-
null = false
3952+
null = true
39523953
type = mediumtext
39533954
comment = "frontend schema for this snapshot"
39543955
}
@@ -4010,7 +4011,7 @@ table "workflow_version" {
40104011
comment = "Version Description"
40114012
}
40124013
column "canvas" {
4013-
null = false
4014+
null = true
40144015
type = mediumtext
40154016
comment = "Front end schema"
40164017
}

0 commit comments

Comments
 (0)