Skip to content

Commit

Permalink
switch from upper case to lower case for mysql tables/columns
Browse files Browse the repository at this point in the history
  • Loading branch information
vkuznet committed Jan 4, 2024
1 parent 2bd8db6 commit a58b61e
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 124 deletions.
16 changes: 8 additions & 8 deletions web/filesdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func InsertFiles(did, dataset, path string) error {
log.Printf("InsertFiles: dataset=%s did=%s", dataset, did)

// check if we have already our dataset in DB
dstmt := "SELECT DID FROM METADATA M JOIN DATASETS D ON M.META_ID=D.META_ID WHERE D.DATASET=? AND M.DID=?"
dstmt := "SELECT did FROM metadata M JOIN datasets D ON M.meta_id=D.meta_id WHERE D.dataset=? AND M.did=?"
DID, e := findDID(dstmt, dataset, did)
if e == nil && DID == did {
return nil
Expand All @@ -171,14 +171,14 @@ func InsertFiles(did, dataset, path string) error {
modify_by := "MetaData server"

// insert main attributes
stmt = "INSERT INTO METADATA (DID,CREATE_AT,CREATE_BY,MODIFY_AT,MODIFY_BY) VALUES (?,?,?,?,?)"
stmt = "INSERT INTO metadata (did,create_at,create_by,modify_at,modify_by) VALUES (?,?,?,?,?)"
_, err = tx.Exec(stmt, did, create_at, create_by, modify_at, modify_by)
if err != nil && !strings.Contains(err.Error(), "UNIQUE") {
log.Printf("ERROR: unable to execute %s with %v, error=%v", stmt, did, err)
return tx.Rollback()
}

stmt = "SELECT META_ID FROM METADATA WHERE DID=?"
stmt = "SELECT meta_id FROM metadata WHERE did=?"
res, err = execute(tx, stmt, did)
if err != nil {
log.Printf("ERROR: unable to execute %s with %v, error=%v", stmt, did, err)
Expand All @@ -188,15 +188,15 @@ func InsertFiles(did, dataset, path string) error {
metaId := rec["meta_id"].(int64)

// insert main attributes
stmt = "INSERT INTO DATASETS (DATASET,META_ID,CREATE_AT,CREATE_BY,MODIFY_AT,MODIFY_BY) VALUES (?,?,?,?,?,?)"
stmt = "INSERT INTO datasets (dataset,meta_id,create_at,create_by,modify_at,modify_by) VALUES (?,?,?,?,?,?)"
_, err = tx.Exec(stmt, dataset, metaId, create_at, create_by, modify_at, modify_by)
if err != nil && !strings.Contains(err.Error(), "UNIQUE") {
log.Printf("ERROR: unable to execute %s with %v, error=%v", stmt, dataset, err)
return tx.Rollback()
}

// select main attributes ids
stmt = "SELECT DATASET_ID FROM DATASETS WHERE DATASET=?"
stmt = "SELECT dataset_id FROM datasets WHERE dataset=?"
res, err = execute(tx, stmt, dataset)
if err != nil {
log.Printf("ERROR: unable to execute %s with %v, error=%v", stmt, dataset, err)
Expand All @@ -207,7 +207,7 @@ func InsertFiles(did, dataset, path string) error {

// insert files info
for _, fname := range files {
stmt = "INSERT INTO FILES (FILE,META_ID,DATASET_ID,CREATE_AT,CREATE_BY,MODIFY_AT,MODIFY_BY) VALUES (?,?,?,?,?,?,?)"
stmt = "INSERT INTO files (file,meta_id,dataset_id,create_at,create_by,modify_at,modify_by) VALUES (?,?,?,?,?,?,?)"
_, err = tx.Exec(stmt, fname, metaId, datasetId, create_at, create_by, modify_at, modify_by)
if err != nil && !strings.Contains(err.Error(), "UNIQUE") {
log.Printf("ERROR: unable to execute %s with did=%v name=%s error=%v", stmt, did, fname, err)
Expand Down Expand Up @@ -235,7 +235,7 @@ func getFiles(did string) ([]string, error) {
defer tx.Rollback()
// look-up files info
// stmt := "SELECT name FROM files WHERE meta_id=?"
stmt := "SELECT F.FILE FROM FILES F JOIN METADATA M ON M.META_ID=F.META_ID WHERE M.DID=?"
stmt := "SELECT F.file FROM files F JOIN metadata M ON M.meta_id=F.meta_id WHERE M.did=?"
res, err := tx.Query(stmt, did)
if err != nil {
log.Printf("ERROR: unable to execute %s, error=%v", stmt, err)
Expand Down Expand Up @@ -292,7 +292,7 @@ func getDatasets() ([]string, error) {
}
defer tx.Rollback()
// dataset is a /cycle/beamline/BTR/sample
stmt := "SELECT D.DATASET FROM DATASETS D"
stmt := "SELECT D.dataset FROM datasets D"
res, err := tx.Query(stmt)
if err != nil {
log.Printf("ERROR: unable to execute %s, error=%v", stmt, err)
Expand Down
116 changes: 58 additions & 58 deletions web/schemas/mysql.sql
Original file line number Diff line number Diff line change
@@ -1,65 +1,65 @@
CREATE TABLE PROCESSING (
PROCESSING_ID INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY,
PROCESSING VARCHAR(255) NOT NULL UNIQUE,
CREATE_AT INTEGER,
CREATE_BY VARCHAR(255),
MODIFY_AT INTEGER,
MODIFY_BY VARCHAR(255)
CREATE TABLE processing (
processing_id INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY,
processing VARCHAR(255) NOT NULL UNIQUE,
create_at INTEGER,
create_by VARCHAR(255),
modify_at INTEGER,
modify_by VARCHAR(255)
);
CREATE TABLE PARENTS (
PARENT_ID INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY,
PARENT VARCHAR(255) NOT NULL UNIQUE,
CREATE_AT INTEGER,
CREATE_BY VARCHAR(255),
MODIFY_AT INTEGER,
MODIFY_BY VARCHAR(255)
CREATE TABLE parents (
parent_id INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY,
parent VARCHAR(255) NOT NULL UNIQUE,
create_at INTEGER,
create_by VARCHAR(255),
modify_at INTEGER,
modify_by VARCHAR(255)
);
CREATE TABLE SITES (
SITE_ID INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY,
SITE VARCHAR(255) NOT NULL UNIQUE,
CREATE_AT INTEGER,
CREATE_BY VARCHAR(255),
MODIFY_AT INTEGER,
MODIFY_BY VARCHAR(255)
CREATE TABLE site (
site_id INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY,
site VARCHAR(255) NOT NULL UNIQUE,
create_at INTEGER,
create_by VARCHAR(255),
modify_at INTEGER,
modify_by VARCHAR(255)
);
CREATE TABLE BUCKETS (
BUCKET_ID INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY,
BUCKET VARCHAR(255) NOT NULL UNIQUE,
META_ID VARCHAR(255),
DATASET_ID BIGINT REFERENCES DATASETS(DATASET_ID) ON UPDATE CASCADE,
CREATE_AT INTEGER,
CREATE_BY VARCHAR(255),
MODIFY_AT INTEGER,
MODIFY_BY VARCHAR(255)
CREATE TABLE buckets (
bucket_id INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY,
bucket VARCHAR(255) NOT NULL UNIQUE,
meta_id VARCHAR(255),
dataset_id BIGINT REFERENCES datasets(dataset_id) ON UPDATE CASCADE,
create_at INTEGER,
create_by VARCHAR(255),
modify_at INTEGER,
modify_by VARCHAR(255)
);
CREATE TABLE METADATA (
META_ID INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY,
DID VARCHAR(255) NOT NULL UNIQUE,
CREATE_AT INTEGER,
CREATE_BY VARCHAR(255),
MODIFY_AT INTEGER,
MODIFY_BY VARCHAR(255)
CREATE TABLE metadata (
meta_id INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY,
did VARCHAR(255) NOT NULL UNIQUE,
create_at INTEGER,
create_by VARCHAR(255),
modify_at INTEGER,
modify_by VARCHAR(255)
);
CREATE TABLE DATASETS (
DATASET_ID INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY,
DATASET VARCHAR(255) NOT NULL UNIQUE,
META_ID BIGINT REFERENCES METADATA(META_ID) ON UPDATE CASCADE,
SITE_ID BIGINT REFERENCES SITES(SITE_ID) ON UPDATE CASCADE,
PROCESSING_ID BIGINT REFERENCES PROCESSINGS(PROCESSING_ID) ON UPDATE CASCADE,
PARENT_ID BIGINT REFERENCES PARENTS(PARENT_ID) ON UPDATE CASCADE,
CREATE_AT INTEGER,
CREATE_BY VARCHAR(255),
MODIFY_AT INTEGER,
MODIFY_BY VARCHAR(255)
CREATE TABLE datasets (
dataset_id INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY,
dataset VARCHAR(255) NOT NULL UNIQUE,
meta_id BIGINT REFERENCES metadata(meta_id) ON UPDATE CASCADE,
site_id BIGINT REFERENCES site(site_id) ON UPDATE CASCADE,
processing_id BIGINT REFERENCES processingS(processing_id) ON UPDATE CASCADE,
parent_id BIGINT REFERENCES parents(parent_id) ON UPDATE CASCADE,
create_at INTEGER,
create_by VARCHAR(255),
modify_at INTEGER,
modify_by VARCHAR(255)
);
CREATE TABLE FILES (
FILE_ID INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY,
FILE VARCHAR(255) NOT NULL UNIQUE,
IS_FILE_VALID INTEGER DEFAULT 1,
META_ID BIGINT REFERENCES METADATA(META_ID) ON UPDATE CASCADE,
DATASET_ID BIGINT REFERENCES DATASETS(DATASET_ID) ON UPDATE CASCADE,
CREATE_AT INTEGER,
CREATE_BY VARCHAR(255),
MODIFY_AT INTEGER,
MODIFY_BY VARCHAR(255)
CREATE TABLE files (
file_id INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY,
file VARCHAR(255) NOT NULL UNIQUE,
is_file_valid INTEGER DEFAULT 1,
meta_id BIGINT REFERENCES metadata(meta_id) ON UPDATE CASCADE,
dataset_id BIGINT REFERENCES datasets(dataset_id) ON UPDATE CASCADE,
create_at INTEGER,
create_by VARCHAR(255),
modify_at INTEGER,
modify_by VARCHAR(255)
);
116 changes: 58 additions & 58 deletions web/schemas/sqlite.sql
Original file line number Diff line number Diff line change
@@ -1,67 +1,67 @@
--https://stackoverflow.com/questions/18387209/sqlite-syntax-for-creating-table-with-foreign-key

CREATE TABLE PROCESSING (
PROCESSING_ID INTEGER PRIMARY KEY AUTOINCREMENT,
PROCESSING VARCHAR(255) NOT NULL UNIQUE,
CREATE_AT INTEGER,
CREATE_BY VARCHAR(255),
MODIFY_AT INTEGER,
MODIFY_BY VARCHAR(255)
create TABLE processing (
processing_id INTEGER PRIMARY KEY AUTOINCREMENT,
processing VARCHAR(255) NOT NULL UNIQUE,
create_at INTEGER,
create_by VARCHAR(255),
modify_at INTEGER,
modify_by VARCHAR(255)
);
CREATE TABLE PARENTS (
PARENT_ID INTEGER PRIMARY KEY AUTOINCREMENT,
PARENT VARCHAR(255) NOT NULL UNIQUE,
CREATE_AT INTEGER,
CREATE_BY VARCHAR(255),
MODIFY_AT INTEGER,
MODIFY_BY VARCHAR(255)
create TABLE parents (
parent_id INTEGER PRIMARY KEY AUTOINCREMENT,
parent VARCHAR(255) NOT NULL UNIQUE,
create_at INTEGER,
create_by VARCHAR(255),
modify_at INTEGER,
modify_by VARCHAR(255)
);
CREATE TABLE SITES (
SITE_ID INTEGER PRIMARY KEY AUTOINCREMENT,
SITE VARCHAR(255) NOT NULL UNIQUE,
CREATE_AT INTEGER,
CREATE_BY VARCHAR(255),
MODIFY_AT INTEGER,
MODIFY_BY VARCHAR(255)
create TABLE sites (
site_id INTEGER PRIMARY KEY AUTOINCREMENT,
site VARCHAR(255) NOT NULL UNIQUE,
create_at INTEGER,
create_by VARCHAR(255),
modify_at INTEGER,
modify_by VARCHAR(255)
);
CREATE TABLE BUCKETS (
BUCKET_ID INTEGER PRIMARY KEY AUTOINCREMENT,
BUCKET VARCHAR(255) NOT NULL UNIQUE,
META_ID VARCHAR(255),
DATASET_ID INTEGER REFERENCES DATASETS(DATASET_ID) ON UPDATE CASCADE,
CREATE_AT INTEGER,
CREATE_BY VARCHAR(255),
MODIFY_AT INTEGER,
MODIFY_BY VARCHAR(255)
create TABLE buckets (
bucket_id INTEGER PRIMARY KEY AUTOINCREMENT,
bucket VARCHAR(255) NOT NULL UNIQUE,
meta_id VARCHAR(255),
dataset_id INTEGER REFERENCES datasets(dataset_id) ON UPDATE CASCADE,
create_at INTEGER,
create_by VARCHAR(255),
modify_at INTEGER,
modify_by VARCHAR(255)
);
CREATE TABLE METADATA (
META_ID INTEGER PRIMARY KEY AUTOINCREMENT,
DID VARCHAR(255) NOT NULL UNIQUE,
CREATE_AT INTEGER,
CREATE_BY VARCHAR(255),
MODIFY_AT INTEGER,
MODIFY_BY VARCHAR(255)
create TABLE metadata (
meta_id INTEGER PRIMARY KEY AUTOINCREMENT,
did VARCHAR(255) NOT NULL UNIQUE,
create_at INTEGER,
create_by VARCHAR(255),
modify_at INTEGER,
modify_by VARCHAR(255)
);
CREATE TABLE DATASETS (
DATASET_ID INTEGER PRIMARY KEY AUTOINCREMENT,
DATASET VARCHAR(255) NOT NULL UNIQUE,
META_ID INTEGER REFERENCES METADATA(META_ID) ON UPDATE CASCADE,
SITE_ID INTEGER REFERENCES SITES(SITE_ID) ON UPDATE CASCADE,
PROCESSING_ID INTEGER REFERENCES PROCESSINGS(PROCESSING_ID) ON UPDATE CASCADE,
PARENT_ID INTEGER REFERENCES PARENTS(PARENT_ID) ON UPDATE CASCADE,
CREATE_AT INTEGER,
CREATE_BY VARCHAR(255),
MODIFY_AT INTEGER,
MODIFY_BY VARCHAR(255)
create TABLE datasets (
dataset_id INTEGER PRIMARY KEY AUTOINCREMENT,
dataset VARCHAR(255) NOT NULL UNIQUE,
meta_id INTEGER REFERENCES metadata(meta_id) ON UPDATE CASCADE,
site_id INTEGER REFERENCES sites(site_id) ON UPDATE CASCADE,
processing_id INTEGER REFERENCES processingS(processing_id) ON UPDATE CASCADE,
parent_id INTEGER REFERENCES parents(parent_id) ON UPDATE CASCADE,
create_at INTEGER,
create_by VARCHAR(255),
modify_at INTEGER,
modify_by VARCHAR(255)
);
CREATE TABLE FILES (
FILE_ID INTEGER PRIMARY KEY AUTOINCREMENT,
FILE VARCHAR(255) NOT NULL UNIQUE,
IS_FILE_VALID INTEGER DEFAULT 1,
META_ID INTEGER REFERENCES METADATA(META_ID) ON UPDATE CASCADE,
DATASET_ID INTEGER REFERENCES DATASETS(DATASET_ID) ON UPDATE CASCADE,
CREATE_AT INTEGER,
CREATE_BY VARCHAR(255),
MODIFY_AT INTEGER,
MODIFY_BY VARCHAR(255)
create TABLE files (
file_id INTEGER PRIMARY KEY AUTOINCREMENT,
file VARCHAR(255) NOT NULL UNIQUE,
is_file_valid INTEGER DEFAULT 1,
meta_id INTEGER REFERENCES metadata(meta_id) ON UPDATE CASCADE,
dataset_id INTEGER REFERENCES datasets(dataset_id) ON UPDATE CASCADE,
create_at INTEGER,
create_by VARCHAR(255),
modify_at INTEGER,
modify_by VARCHAR(255)
);

0 comments on commit a58b61e

Please sign in to comment.