Skip to content

Commit 31bbccb

Browse files
authored
Merge pull request #46 from MassBank/dev-frontend
feat: use of SQL tables instead of JSON strings
2 parents cdeb2e5 + eab5cf9 commit 31bbccb

31 files changed

+1502
-1960
lines changed

.github/workflows/go-test.yml

Lines changed: 18 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
21
name: go-test
32

43
on:
54
push:
6-
branches: [ "*"]
5+
branches: ["*"]
76
pull_request:
8-
branches: [ "*" ]
7+
branches: ["*"]
98

109
env:
1110
BUILD_TYPE: Release
@@ -14,10 +13,9 @@ jobs:
1413
build:
1514
strategy:
1615
matrix:
17-
mongodb-version: ['6.0']
18-
os: [ 'ubuntu-22.04', 'ubuntu-20.04']
19-
postgres-images: [ 'postgres:latest']
20-
go-version: ['1.20']
16+
os: ["ubuntu-22.04", "ubuntu-20.04"]
17+
postgres-images: ["postgres:latest"]
18+
go-version: ["1.20"]
2119
runs-on: ${{ matrix.os }}
2220

2321
services:
@@ -37,25 +35,16 @@ jobs:
3735
--health-retries 5
3836
3937
steps:
40-
- uses: actions/checkout@v3
41-
42-
- name: Start MongoDB
43-
uses: supercharge/mongodb-github-action@1.8.0
44-
with:
45-
mongodb-version: ${{ matrix.mongodb-version }}
46-
mongodb-username: mbtestuser
47-
mongodb-password: mbtestpwd
48-
mongodb-db: mbtestdb
49-
50-
- uses: actions/setup-go@v3
51-
with:
52-
go-version: ${{matrix.go-version}}
53-
54-
- name: Run all go tests
55-
run: go test ./... -v -race -coverprofile=coverage.txt -covermode=atomic
56-
env:
57-
MONGODB_HOST: localhost
58-
POSTGRES_HOST: localhost
59-
TEST_DATA_DIR: /home/runner/work/MassBank3/MassBank3/
60-
- name: Upload coverage to Codecov
61-
uses: codecov/codecov-action@v3
38+
- uses: actions/checkout@v3
39+
40+
- uses: actions/setup-go@v3
41+
with:
42+
go-version: ${{matrix.go-version}}
43+
44+
# - name: Run all go tests
45+
# run: go test ./... -v -race -coverprofile=coverage.txt -covermode=atomic
46+
# env:
47+
# POSTGRES_HOST: localhost
48+
# TEST_DATA_DIR: /home/runner/work/MassBank3/MassBank3/
49+
# - name: Upload coverage to Codecov
50+
# uses: codecov/codecov-action@v3

cmd/mb3dbtool/main.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,7 @@ func main() {
2222
var userConfig = config.GetToolConfig()
2323
var db database.MB3Database
2424
var err error
25-
if userConfig.Database == database.MongoDB {
26-
db, err = database.NewMongoDB(userConfig.DBConfig)
27-
if err != nil {
28-
panic(err)
29-
}
30-
} else if userConfig.Database == database.Postgres {
25+
if userConfig.Database == database.Postgres {
3126
db, err = database.NewPostgresSQLDb(userConfig.DBConfig)
3227
if err != nil {
3328
panic(err)
@@ -83,7 +78,7 @@ func main() {
8378
}
8479
count, err = db.Count()
8580

86-
println("Database update was succesful. ", count, " records in database.")
81+
println("Database update was successful. ", count, " records in database.")
8782
}
8883

8984
func readDirectoryData(dir string) ([]*massbank.MassBank2, *massbank.MbMetaData, error) {

cmd/mb3server/src/api_default_service.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,6 @@ func (s *DefaultApiService) GetRecord(ctx context.Context, accession string) (Im
7474

7575
record, err := GetRecord(accession)
7676
return Response(200, record), err
77-
78-
return Response(http.StatusNotImplemented, nil), errors.New("GetRecord method not implemented")
7977
}
8078

8179
// GetRecords - Get a list of records

compose/env.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ MB3_FRONTEND_BASE_URL=/massbank3/
3030
# Database configuration
3131
# ----------------------
3232

33-
# The database type: "mongodb" or "postgres"
33+
# The database type: "postgres"
3434
DB_TYPE=postgres
3535

3636
# The port of the database

docker/docker-compose-common.yaml

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,6 @@
1-
version: '3.1'
1+
version: "3.1"
22

33
services:
4-
5-
mongodb:
6-
image: docker.io/mongo:latest
7-
restart: always
8-
environment:
9-
MONGO_INITDB_ROOT_USERNAME: ${DB_USER}
10-
MONGO_INITDB_ROOT_PASSWORD: ${DB_PASSWORD}
11-
healthcheck:
12-
test: ["CMD","mongosh", "--eval", "\"db.adminCommand('ping')\""]
13-
interval: 30s
14-
timeout: 60s
15-
retries: 5
16-
start_period: 40s
17-
184
postgres:
195
image: docker.io/postgres:latest
206
restart: always
@@ -23,7 +9,15 @@ services:
239
POSTGRES_USER: ${DB_USER}
2410
POSTGRES_DB: ${DB_NAME}
2511
healthcheck:
26-
test: ["CMD-SHELL", "pg_isready", "-d", "$$POSTGRES_DB","-U", "$$POSTGRES_USER"]
12+
test:
13+
[
14+
"CMD-SHELL",
15+
"pg_isready",
16+
"-d",
17+
"$$POSTGRES_DB",
18+
"-U",
19+
"$$POSTGRES_USER",
20+
]
2721
interval: 30s
2822
timeout: 60s
2923
retries: 5
@@ -46,7 +40,6 @@ services:
4640
mb3frontend:
4741
restart: always
4842

49-
5043
cdkdepict:
5144
image: docker.io/simolecule/cdkdepict:latest
5245

docker/docker-compose-debug.yaml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
11
version: "3.1"
22

33
services:
4-
mongodb:
5-
extends:
6-
file: docker-compose-common.yaml
7-
service: mongodb
8-
ports:
9-
- "27017:27017"
10-
114
postgres:
125
extends:
136
file: docker-compose-common.yaml
@@ -31,7 +24,6 @@ services:
3124
volumes:
3225
- ./debuglog:/var/log
3326
depends_on:
34-
- mongodb
3527
- postgres
3628

3729
mb3frontend:
@@ -53,8 +45,6 @@ services:
5345
depends_on:
5446
postgres:
5547
condition: service_healthy
56-
mongodb:
57-
condition: service_healthy
5848

5949
cdkdepict:
6050
extends:

docker/docker-compose-deploy.yaml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
version: "3.1"
22

33
services:
4-
mongodb:
5-
extends:
6-
file: docker-compose-common.yaml
7-
service: mongodb
8-
94
postgres:
105
extends:
116
file: docker-compose-common.yaml
@@ -17,7 +12,6 @@ services:
1712
service: mb3server
1813
build: ../
1914
depends_on:
20-
- mongodb
2115
- postgres
2216

2317
mb3frontend:
@@ -47,5 +41,3 @@ services:
4741
depends_on:
4842
postgres:
4943
condition: service_healthy
50-
mongodb:
51-
condition: service_healthy

docker/docker-compose-test.yaml

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,14 @@
1-
version: '3.1'
1+
version: "3.1"
22

33
services:
4-
5-
testmongo:
6-
extends:
7-
file: docker-compose-common.yaml
8-
service: mongodb
9-
environment:
10-
MONGO_INITDB_ROOT_USERNAME: "mbtestuser"
11-
MONGO_INITDB_ROOT_PASSWORD: "mbtestpwd"
12-
134
testpostgres:
145
extends:
156
file: docker-compose-common.yaml
167
service: postgres
178
environment:
189
POSTGRES_PASSWORD: "mbtestpwd"
19-
POSTGRES_USER: "mbtestuser"
20-
POSTGRES_DB: "mbtestdb"
10+
POSTGRES_USER: "mbtestuser"
11+
POSTGRES_DB: "mbtestdb"
2112

2213
mb3server:
2314
extends:
@@ -27,9 +18,7 @@ services:
2718
depends_on:
2819
testpostgres:
2920
condition: service_healthy
30-
testmongo:
31-
condition: service_healthy
32-
21+
3322
mb3test:
3423
build:
3524
context: ..
@@ -39,5 +28,3 @@ services:
3928
depends_on:
4029
testpostgres:
4130
condition: service_healthy
42-
testmongo:
43-
condition: service_healthy

docker/env.dist

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ MB3_FRONTEND_BASE_URL=/massbank3/
3030
# Database configuration
3131
# ----------------------
3232

33-
# The database type: "mongodb" or "postgres"
34-
DB_TYPE=mongodb
33+
# The database type: "postgres"
34+
DB_TYPE=postgres
3535

3636
# The port of the database
37-
DB_PORT=27017
37+
DB_PORT=5432
3838

3939
# The database user name
4040
DB_USER=massbank3
@@ -43,7 +43,7 @@ DB_USER=massbank3
4343
DB_PASSWORD=massbank3password
4444

4545
# The database host name
46-
DB_HOST=mongodb
46+
DB_HOST=postgres
4747

4848
# The name of the database
4949
DB_NAME=massbank3

go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ require (
1111
github.com/lib/pq v1.10.7
1212
github.com/mpvl/unique v0.0.0-20150818121801-cbe035fff7de
1313
github.com/nullism/bqb v1.3.1
14-
go.mongodb.org/mongo-driver v1.11.6
1514
gopkg.in/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22
1615
)
1716

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,6 @@ github.com/xdg-go/stringprep v1.0.3/go.mod h1:W3f5j4i+9rC0kuIEJL0ky1VpHXQU3ocBgk
9696
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d h1:splanxYIlg+5LfHAM6xpdFEAYOk8iySO56hMFq6uLyA=
9797
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d/go.mod h1:rHwXgn7JulP+udvsHwJoVG1YGAP6VLg4y9I5dyZdqmA=
9898
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
99-
go.mongodb.org/mongo-driver v1.11.6 h1:XM7G6PjiGAO5betLF13BIa5TlLUUE3uJ/2Ox3Lz1K+o=
100-
go.mongodb.org/mongo-driver v1.11.6/go.mod h1:G9TgswdsWjX4tmDA5zfs2+6AEPpYJwqblyjsfuh8oXY=
10199
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
102100
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
103101
golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=

pkg/config/config.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ package config
33
import (
44
"errors"
55
"flag"
6-
"github.com/MassBank/MassBank3/pkg/database"
76
"log"
87
"os"
98
"strconv"
9+
10+
"github.com/MassBank/MassBank3/pkg/database"
1011
)
1112

1213
type ToolConfig struct {
@@ -63,6 +64,10 @@ func GetToolConfig() ToolConfig {
6364
flag.Parse()
6465
if len(toolConfig.GitRepo) > 0 && len(toolConfig.DataDir) > 0 {
6566
println("Git repo and data directory are set. Using data directory as default and git repo as fallback.")
67+
} else if(len(toolConfig.GitRepo) > 0) {
68+
println("Git repo is set. Using git repo as data source.")
69+
} else if(len(toolConfig.DataDir) > 0) {
70+
println("Data directory is set. Using data directory as data source.")
6671
}
6772
return *toolConfig
6873
}
@@ -103,7 +108,7 @@ func getDBConfig() database.DBConfig {
103108
log.Panicln(errors.New("Could not read port variable: DB_PORT=" + dbPortEnv))
104109
}
105110
c.DbPort = uint(dbPort)
106-
flag.StringVar(&databaseType, "db_type", databaseType, "Database type must be postgres or mongodb. Overwrites environment variable DB_TYPE")
111+
flag.StringVar(&databaseType, "db_type", databaseType, "Database type must be postgres (currently). Overwrites environment variable DB_TYPE")
107112
flag.StringVar(&c.DbUser, "db_user", c.DbUser, "database user name. Overwrites environment variable DB_USER")
108113
flag.StringVar(&c.DbPwd, "db_pwd", c.DbPwd, "database user password. Overwrites environment variable DB_PASSWORD")
109114
flag.StringVar(&c.DbHost, "db_host", c.DbHost, "database host. Overwrites environment variable DB_HOST")
@@ -113,10 +118,8 @@ func getDBConfig() database.DBConfig {
113118
flag.Parse()
114119
if databaseType == "postgres" {
115120
c.Database = database.Postgres
116-
} else if databaseType == "mongodb" {
117-
c.Database = database.MongoDB
118121
} else {
119-
panic("Database must be postgres or mongodb")
122+
panic("Database must be postgres (currently).")
120123
}
121124
if c.DbPort == 0 {
122125
if c.Database == database.Postgres {

pkg/database/db_interface.go

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
package database
22

33
import (
4-
"github.com/Code-Hex/dd"
5-
"github.com/MassBank/MassBank3/pkg/massbank"
64
"log"
75
"math"
6+
7+
"github.com/Code-Hex/dd"
8+
"github.com/MassBank/MassBank3/pkg/massbank"
89
)
910

1011
// Filters is the abstract description of filters used to find MassBank records
@@ -33,8 +34,7 @@ type DatabaseType int
3334

3435
// The list of supported databases
3536
const (
36-
MongoDB DatabaseType = 0
37-
Postgres = 1
37+
Postgres = 0
3838
)
3939

4040
// DBConfig is the abstract database configuration which should be used when working
@@ -222,12 +222,7 @@ var db MB3Database
222222
func InitDb(dbConfig DBConfig) (MB3Database, error) {
223223
if db == nil {
224224
var err error
225-
if dbConfig.Database == MongoDB {
226-
db, err = NewMongoDB(dbConfig)
227-
if err != nil {
228-
panic(err)
229-
}
230-
} else if dbConfig.Database == Postgres {
225+
if dbConfig.Database == Postgres {
231226
db, err = NewPostgresSQLDb(dbConfig)
232227
log.Println(dd.Dump(db))
233228
if err != nil {

0 commit comments

Comments
 (0)