-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
256 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Set to ignore everything except /src and package.json | ||
* | ||
!src | ||
!package.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,33 @@ | ||
version: "3.8" | ||
|
||
services: | ||
|
||
# access through `psql -h localhost -p 5432 -d filesync -U user`, password is 'pass' | ||
# to be able to build after the initializing the db, you may need to run `sudo chown -R $USER db_data/` | ||
database: | ||
image: 'postgres:13' | ||
env_file: ./.env | ||
volumes: | ||
- ./postgres/db_data/:/var/lib/postgresql/data/ | ||
- ./postgres/init/create_tables.sql:/docker-entrypoint-initdb.d/create_tables.sql | ||
ports: | ||
- ${PORT_DB}:${PORT_DB} | ||
|
||
server: | ||
build: | ||
context: . | ||
dockerfile: Dockerfile | ||
depends_on: | ||
- database | ||
env_file: ./.env | ||
volumes: | ||
- ./src/build:/ffs/ | ||
- /ffs/node_modules | ||
- ./FileShare:/ffs/FileShare/ | ||
- ./file_share:/ffs/file_share/ | ||
- ${LOCAL_DIR_GANTRY}:/ffs/file_share/Gantry/ | ||
- ${LOCAL_DIR_MILL}:/ffs/file_share/Mill/ | ||
- ${LOCAL_DIR_LATHE}:/ffs/file_share/Lathe/ | ||
- ${LOCAL_DIR_WATERJET}:/ffs/file_share/Waterjet/ | ||
ports: | ||
- ${PORT}:${PORT} | ||
command: "node server.js" | ||
|
||
# task_runner_gantry: | ||
# build: | ||
# context: . | ||
# dockerfile: Dockerfile | ||
# env_file: ./.env | ||
# volumes: | ||
# - ./src/build:/ffs/ | ||
# - /ffs/node_modules | ||
# - ${LOCAL_DIR_GANTRY}:/ffs/FileShare/Gantry | ||
# network_mode: host | ||
# command: "node taskRunner.js gantry" | ||
# | ||
# task_runner_lathe: | ||
# build: | ||
# context: . | ||
# dockerfile: Dockerfile | ||
# env_file: ./.env | ||
# volumes: | ||
# - ./src/build:/ffs/ | ||
# - /ffs/node_modules | ||
# - ${LOCAL_DIR_LATHE}:/ffs/FileShare/Lathe | ||
# network_mode: host | ||
# command: "node taskRunner.js lathe" | ||
|
||
# task_runner_mill: | ||
# build: | ||
# context: . | ||
# dockerfile: Dockerfile | ||
# env_file: ./.env | ||
# volumes: | ||
# - ./src/build:/ffs/ | ||
# - /ffs/node_modules | ||
# - ${LOCAL_DIR_MILL}:/ffs/FileShare/Mill | ||
# network_mode: host | ||
# command: "node taskRunner.js mill" | ||
|
||
# task_runner_waterjet: | ||
# build: | ||
# context: . | ||
# dockerfile: Dockerfile | ||
# env_file: ./.env | ||
# volumes: | ||
# - ./src/build:/ffs/ | ||
# - /ffs/node_modules | ||
# - ${LOCAL_DIR_WATERJET}:/ffs/FileShare/Waterjet | ||
# network_mode: host | ||
# command: "node taskRunner.js waterjet" | ||
- ${PORT_SERVER}:${PORT_SERVER} | ||
command: "node server.js" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
-- Primary keys must include folder name in order to avoid collisions | ||
-- between filenames in different folders | ||
|
||
CREATE TABLE IF NOT EXISTS fusion ( | ||
fusion_id varchar(250) NOT NULL, | ||
folder_name varchar(250) NOT NULL, | ||
file_name varchar(250) NOT NULL, | ||
username varchar(250), | ||
size int, | ||
version int, | ||
PRIMARY KEY (fusion_id) | ||
); | ||
|
||
CREATE TABLE IF NOT EXISTS local ( | ||
file_name varchar(250) NOT NULL, | ||
folder_name varchar(250) NOT NULL, | ||
fusion_id varchar(250), | ||
PRIMARY KEY (file_name, folder_name) | ||
); | ||
|
||
CREATE TABLE IF NOT EXISTS archive ( | ||
fusion_id varchar(250) NOT NULL, | ||
file_name varchar(250) NOT NULL, | ||
folder_name varchar(250) NOT NULL, | ||
username varchar(250) NOT NULL, | ||
size int, | ||
version int, | ||
PRIMARY KEY (fusion_id, folder_name) | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
import { Client, Query } from 'ts-postgres'; | ||
import { createPool } from 'generic-pool'; | ||
import * as config from './config'; | ||
|
||
const pool = createPool({ | ||
create: async () => { | ||
return new Promise<Client>((resolve, reject) => { | ||
|
||
const client = new Client({ | ||
'host': 'database', // name of docker container, not 'localhost' | ||
'port': config.postgresPort, | ||
'user': config.postgresUser, | ||
'password': config.postgresPassword, | ||
'database': config.postgresDB | ||
}); | ||
|
||
client.connect() | ||
.then(() => { | ||
console.log("successfully connected to db") | ||
resolve(client); | ||
}).catch((err: any) => { | ||
console.log() | ||
console.log(err) | ||
reject(err); | ||
}); | ||
}); | ||
}, | ||
destroy: async (client: Client) => { | ||
return client.end() | ||
}, | ||
validate: (client: Client) => { | ||
return Promise.resolve(!client.closed); | ||
} | ||
}, { | ||
testOnBorrow: true, | ||
max: 10 | ||
}) | ||
|
||
const executeQuery = (query: Query) => { | ||
console.log('executing query'); | ||
|
||
const res = pool.acquire(); | ||
|
||
return res.then(async (client: Client) => { | ||
console.log('aquired client from pool') | ||
const result = await client.execute(query); | ||
pool.release(client).then(() => { | ||
console.log("client released back into pool") | ||
}); | ||
return result; | ||
}).catch((err: any) => { | ||
console.log(err); | ||
}) | ||
} | ||
|
||
export const shutdown = () => { | ||
pool.drain() | ||
.then(() => { | ||
return pool.clear(); | ||
}); | ||
} | ||
|
||
export const insert = (table: string, params: any) => { | ||
|
||
let fileName = params.fileName; | ||
let folderName = params.folderName; | ||
let fusionID = null; | ||
let username = null; | ||
let size = null; | ||
let version = null; | ||
|
||
if (params.hasOwnProperty('fusionID')) {fusionID = params.fusionID} | ||
if (params.hasOwnProperty('username')) {username = params.username} | ||
if (params.hasOwnProperty('size')) {size = params.size} | ||
if (params.hasOwnProperty('version')) {version = params.version} | ||
|
||
let query: Query; | ||
|
||
console.log("params: ", params); | ||
|
||
switch(table) { | ||
case 'fusion': | ||
query = new Query ( | ||
"INSERT INTO fusion (fusion_id, folder_name, file_name, username, size, version)" + | ||
"VALUES ($1, $2, $3, $4, $5, $6)", | ||
[fusionID, folderName, fileName, username, size, version] | ||
); | ||
break; | ||
case 'local': | ||
query = new Query ( | ||
"INSERT INTO local (file_name, folder_name, fusion_id)" + | ||
"VALUES ($1, $2, $3)", | ||
[fileName, folderName, fusionID] | ||
); | ||
break; | ||
case 'archive': | ||
query = new Query ( | ||
"INSERT INTO archive (fusion_id, folder_name, file_name, username, size, version)" + | ||
"VALUES ($1, $2, $3, $4, $5, $6)", | ||
[fusionID, folderName, fileName, username, size, version] | ||
); | ||
break; | ||
default: | ||
throw new Error("Invalid table/params"); | ||
} | ||
|
||
return executeQuery(query); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.