@@ -43,11 +43,11 @@ func NewMariaDB(username string, password string, host string, databaseName stri
43
43
// InitializeSchema initialize the schema of the database
44
44
func (m * MariaDB ) InitializeSchema () error {
45
45
// type must be part of the primary key to be a partition key
46
- q , err := m .db .QueryContext (context .Background (), `
46
+ _ , err := m .db .ExecContext (context .Background (), `
47
47
CREATE TABLE IF NOT EXISTS assets (
48
48
id INT NOT NULL AUTO_INCREMENT,
49
- value VARCHAR(255) NOT NULL,
50
- type VARCHAR(64) NOT NULL,
49
+ value VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL,
50
+ type VARCHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
51
51
52
52
CONSTRAINT pk_asset PRIMARY KEY (id),
53
53
UNIQUE unique_asset_idx (type, value),
@@ -56,21 +56,20 @@ CREATE TABLE IF NOT EXISTS assets (
56
56
if err != nil {
57
57
return err
58
58
}
59
- defer q .Close ()
60
59
61
60
// type must be part of the primary key to be a partition key
62
- q , err = m .db .QueryContext (context .Background (), `
61
+ _ , err = m .db .ExecContext (context .Background (), `
63
62
CREATE TABLE IF NOT EXISTS relations (
64
63
id INT NOT NULL AUTO_INCREMENT,
65
64
from_id INT NOT NULL,
66
65
to_id INT NOT NULL,
67
- type VARCHAR(64) NOT NULL,
68
- source VARCHAR(64) NOT NULL,
66
+ type VARCHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
67
+ source VARCHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
69
68
70
69
CONSTRAINT pk_relation PRIMARY KEY (id),
71
70
CONSTRAINT fk_from FOREIGN KEY (from_id) REFERENCES assets (id),
72
71
CONSTRAINT fk_to FOREIGN KEY (to_id) REFERENCES assets (id),
73
-
72
+
74
73
INDEX full_relation_type_from_to_idx (type, from_id, to_id),
75
74
INDEX full_relation_type_to_from_idx (type, to_id, from_id),
76
75
INDEX full_relation_from_type_to_idx (from_id, type, to_id),
@@ -80,24 +79,22 @@ CREATE TABLE IF NOT EXISTS relations (
80
79
if err != nil {
81
80
return err
82
81
}
83
- defer q .Close ()
84
82
85
83
// Create the table storing the schema graphs
86
- q , err = m .db .QueryContext (context .Background (), `
84
+ _ , err = m .db .ExecContext (context .Background (), `
87
85
CREATE TABLE IF NOT EXISTS graph_schema (
88
86
id INTEGER AUTO_INCREMENT NOT NULL,
89
- importer VARCHAR(64) NOT NULL,
87
+ importer VARCHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
90
88
graph TEXT NOT NULL,
91
89
timestamp TIMESTAMP,
92
-
90
+
93
91
CONSTRAINT pk_schema PRIMARY KEY (id))` )
94
92
if err != nil {
95
93
return err
96
94
}
97
- defer q .Close ()
98
95
99
96
// Create the table storing importers tokens
100
- q , err = m .db .QueryContext (context .Background (), `
97
+ _ , err = m .db .ExecContext (context .Background (), `
101
98
CREATE TABLE IF NOT EXISTS importers (
102
99
id INTEGER AUTO_INCREMENT NOT NULL,
103
100
name VARCHAR(64) NOT NULL,
@@ -109,10 +106,9 @@ CREATE TABLE IF NOT EXISTS importers (
109
106
if err != nil {
110
107
return err
111
108
}
112
- defer q .Close ()
113
109
114
110
// Create the table storing importers tokens
115
- q , err = m .db .QueryContext (context .Background (), `
111
+ _ , err = m .db .ExecContext (context .Background (), `
116
112
CREATE TABLE IF NOT EXISTS query_history (
117
113
id INTEGER AUTO_INCREMENT NOT NULL,
118
114
timestamp TIMESTAMP,
@@ -126,7 +122,7 @@ CREATE TABLE IF NOT EXISTS importers (
126
122
if err != nil {
127
123
return err
128
124
}
129
- defer q . Close ()
125
+
130
126
return nil
131
127
}
132
128
0 commit comments