Skip to content

Commit 70ed523

Browse files
committed
don't drop db everytime
1 parent d3da330 commit 70ed523

File tree

5 files changed

+7
-86
lines changed

5 files changed

+7
-86
lines changed

languages/go/goeql

Submodule goeql deleted from 3765997

languages/go/xorm/init-db/init.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/bin/bash
22

33
psql -U $POSTGRES_USER -d postgres -f /app/scripts/db/create-db.sql
4-
psql -U $POSTGRES_USER -d gotest -a -f /app/scripts/db/cipherstash-encrypt.sql
4+
psql -U $POSTGRES_USER -d gotest -a -f /app/scripts/db/cipherstash-encrypt.sql

languages/go/xorm/main.go

Lines changed: 4 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -123,44 +123,6 @@ func (eb *EncryptedBoolField) FromDB(data []byte) error {
123123
return nil
124124
}
125125

126-
func setupDb() {
127-
connStr := "user=postgres password=postgres port=5432 host=localhost dbname=postgres sslmode=disable"
128-
engine, err := xorm.NewEngine("pgx", connStr)
129-
130-
if err != nil {
131-
log.Fatalf("Could not connect to the database: %v", err)
132-
}
133-
134-
var exists bool
135-
_, err = engine.SQL("SELECT EXISTS (SELECT datname FROM pg_catalog.pg_database WHERE datname = 'gotest')").Get(&exists)
136-
if err != nil {
137-
log.Fatalf("Error: %v", err)
138-
}
139-
140-
if exists {
141-
_, err = engine.Exec("DROP DATABASE gotest WITH (FORCE);")
142-
if err != nil {
143-
log.Fatalf("Could not drop database: %v", err)
144-
}
145-
fmt.Println("Database 'gotest' dropped successfully!")
146-
147-
_, err = engine.Exec("CREATE DATABASE gotest;")
148-
if err != nil {
149-
log.Fatalf("Could not create database: %v", err)
150-
}
151-
fmt.Println("Database 'gotest' recreated!")
152-
} else {
153-
fmt.Println("Database 'gotest' doesn't exist. Creating...")
154-
_, err = engine.Exec("CREATE DATABASE gotest;")
155-
if err != nil {
156-
log.Fatalf("Could not create database: %v", err)
157-
}
158-
fmt.Println("Database 'gotest' created successfully!")
159-
}
160-
161-
engine.Close()
162-
}
163-
164126
func createTable() {
165127
connStr := "user=postgres password=postgres port=5432 host=localhost dbname=gotest sslmode=disable"
166128
engine, err := xorm.NewEngine("pgx", connStr)
@@ -182,7 +144,7 @@ func createTable() {
182144
engine.Close()
183145
}
184146

185-
func installEql() {
147+
func addIndexesConstraints() {
186148
connStr := "user=postgres password=postgres port=5432 host=localhost dbname=gotest sslmode=disable"
187149
// Install Eql, custom types, indexes and constraints
188150
// To install our custom types we need to use the database/sql package due to an issue
@@ -192,7 +154,7 @@ func installEql() {
192154
if err != nil {
193155
log.Fatalf("Could not connect to the database: %v", err)
194156
}
195-
InstallEql(engine)
157+
196158
AddIndexes(engine)
197159
AddConstraint(engine)
198160

@@ -219,12 +181,9 @@ func main() {
219181
}
220182

221183
func setupDev() {
222-
// Recreate gotest db on each run
223-
setupDb()
224-
225184
// Connect to go test directly and create table
226185
createTable()
227186

228-
// Install EQL and add config
229-
installEql()
187+
// Add config
188+
addIndexesConstraints()
230189
}

languages/go/xorm/migrations.go

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,8 @@ package main
33
import (
44
"database/sql"
55
"log"
6-
"os"
76
)
87

9-
func InstallEql(engine *sql.DB) {
10-
log.Println("Start installing custom types and function")
11-
installDsl(engine)
12-
13-
}
14-
15-
// Installing EQL
16-
func installDsl(engine *sql.DB) {
17-
path := "../../../release/cipherstash-encrypt-dsl.sql"
18-
sql, err := os.ReadFile(path)
19-
if err != nil {
20-
log.Fatalf("Failed to read SQL file: %v", err)
21-
}
22-
23-
_, err = engine.Exec(string(sql))
24-
if err != nil {
25-
log.Fatalf("Failed to execute SQL query: %v", err)
26-
}
27-
}
28-
298
// We need to add constraints on any column that is encrypted.
309
// This checks that all the required json fields are present, and that the data has been encrypted
3110
// by the proxy before inserting.

languages/go/xorm/run.sh

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ if [ "${BASH_SOURCE[0]}" != "./run.sh" ]; then
1515
fi
1616

1717
subproject_setup() {
18-
# start postgres and proxy
18+
# start postgres and proxy (create db and install eql)
1919
docker compose up -d
20-
# setup table, install eql, constraints and indexes
20+
# constraints and indexes
2121
go run . setupDev
2222
}
2323

@@ -26,19 +26,7 @@ subproject_teardown() {
2626
docker compose down
2727
}
2828

29-
subproject_examples() {
30-
# reset db
31-
go run . setupDev
32-
33-
# run examples queries
34-
go run . runExamples
35-
}
36-
3729
subproject_tests(){
38-
# start postgres and proxy
39-
docker compose up -d
40-
# reset db
41-
go run . setupDev
4230
# run e2e tests
4331
make gotest
4432
}
@@ -53,10 +41,6 @@ case $subcommand in
5341
subproject_teardown
5442
;;
5543

56-
examples)
57-
subproject_examples
58-
;;
59-
6044
tests)
6145
subproject_tests
6246
;;

0 commit comments

Comments
 (0)