diff options
| author | cjd24 | 2018-02-07 03:09:50 +0000 |
|---|---|---|
| committer | cjd24 | 2018-02-07 03:09:50 +0000 |
| commit | d66a0d90a658d5094ba274c4b4c4c3d66d8254a3 (patch) | |
| tree | 997352d8fdc611f7a16df9ed409c706413cd877e | |
| parent | Merge branch 'cjd24/stubsgres' into 'master' (diff) | |
| download | medicine-d66a0d90a658d5094ba274c4b4c4c3d66d8254a3.tar.gz medicine-d66a0d90a658d5094ba274c4b4c4c3d66d8254a3.zip | |
Streamlined script for adding postgres, and added packages in preparation for writing ORM
| -rw-r--r-- | README.md | 10 | ||||
| -rw-r--r-- | Report/report.md | 3 | ||||
| -rwxr-xr-x | getmepostgres.sh | 46 | ||||
| -rw-r--r-- | package.json | 5 | ||||
| -rwxr-xr-x | runmepostgres.sh | 5 | ||||
| -rw-r--r-- | src/db/initPostgresDB.ts | 13 | ||||
| -rw-r--r-- | tsconfig.json | 8 |
7 files changed, 67 insertions, 23 deletions
@@ -5,12 +5,16 @@ $ ./getmenode.sh $ npm install all +## Instructions to install postgres locally (on lab machines): + +$ ./getmepostgres.sh + ## Instructions to execute: $ ./runmenode.sh // alternative for home pc: -$ npm start +$ npm start ## To test: @@ -20,5 +24,5 @@ $ npm test ## Sources: http://mherman.org/blog/2016/11/05/developing-a-restful-api-with-node-and-typescript/#.WlW1fhdpw8o https://basarat.gitbooks.io/typescript/docs/quick/nodejs.html - - +https://github.com/RobinBuschmann/sequelize-typescript +https://sequelize.readthedocs.io/en/v3/ diff --git a/Report/report.md b/Report/report.md index 664b830..8a1c92b 100644 --- a/Report/report.md +++ b/Report/report.md @@ -1,4 +1,5 @@ -# Junior Honours Project 2017 - 2018 +# Junior Honours Project 2017 - 2018 +# BACKEND GROUP 4. > cjd24 - Calum > trh - Tom > har4 - Hafeez diff --git a/getmepostgres.sh b/getmepostgres.sh index 05db59d..50976f8 100755 --- a/getmepostgres.sh +++ b/getmepostgres.sh @@ -6,6 +6,15 @@ if [ -d "~/pg" ]; then exit 1; fi +echo " "; +echo " "; +echo " "; +echo "This installation process takes ~3:50 minutes to complete."; +echo " "; +echo " "; +echo " "; +sleep 3; + echo "> Making postgres directory at ~/pg"; mkdir ~/pg; currentDir=$(pwd); @@ -16,30 +25,39 @@ cd ~/pg; echo "> Cloning Repo"; git clone https://github.com/postgres/postgres.git; -echo "> Checking out to version 10"; +echo "> Checking out to version 10.1"; cd ./postgres; -git reset --hard REL_10_0; +git reset --hard REL_10_1; echo "> Configuring"; -sleep 2; ./configure --prefix=$HOME/pg/postgres/ --with-python PYTHON=/usr/bin/python2.7; - -read -p "Press [Enter] key to Build Postgres..."; echo "> Building Postgres"; make -j 5; -read -p "Press [Enter] key to Install Postgres..."; echo "> Installing Postgres"; make install; -echo "> Creating the Database"; +echo "> Initialise the Database"; ~/pg/postgres/bin/initdb -D ~/pg/postgres/data/; - -echo ""; -echo ""; -echo ""; -echo ""; -echo ""; -echo "> Completed the installation of Postgres. Please use `./runmepostgres.sh` to run."; +echo " "; +echo " "; +echo " "; +echo " "; +echo "> Starting the postgres server"; +~/pg/postgres/bin/pg_ctl -D ~/pg/postgres/data/ -l POSTGRES_logfile start; +echo "> Create the Database"; +~/pg/postgres/bin/createdb be4; +echo "> Creating Admin user"; +~/pg/postgres/bin/psql -U ${USER} postgres -c "CREATE USER admin WITH PASSWORD 'eprprJacR0hBpmWvs5IDJZTnjRAY2gM3tSm0b1af';"; +echo "> Granting Admin Permissions"; +~/pg/postgres/bin/psql -U ${USER} postgres -c "ALTER DATABASE be4 OWNER TO admin;"; + + +echo " "; +echo " "; +echo " "; +echo " "; +echo " "; +echo "> Completed the installation of Postgres."; cd $currentDir; diff --git a/package.json b/package.json index e26c237..2f9c6fd 100644 --- a/package.json +++ b/package.json @@ -2,6 +2,7 @@ "name": "cs3099jhbe4", "description": "2017 Junior Honours Project - Backend Group 4", "main": "index.ts", + "license": "UNLICENSED", "scripts": { "test": "mocha --reporter spec -r ts-node/register 'test/**/*.test.ts'", "start": "ts-node src/index.ts" @@ -37,6 +38,10 @@ "express": "^4.16.2", "morgan": "^1.9.0", "pg": "^7.4.1", + "pg-hstore": "^2.3.2", + "reflect-metadata": "^0.1.12", + "sequelize": "^4.32.7", + "sequelize-typescript": "^0.6.2", "ts-node": "^3.3.0", "typescript": "^2.7.1", "xlsx": "^0.11.19" diff --git a/runmepostgres.sh b/runmepostgres.sh index fb68e5e..632ea66 100755 --- a/runmepostgres.sh +++ b/runmepostgres.sh @@ -1,7 +1,8 @@ #!/bin/bash +read -p "Press [Enter] key to start Postgres (will already be running if you just got it) use ctl+c to cancel"; echo "> Starting Server"; ~/pg/postgres/bin/pg_ctl -D ~/pg/postgres/data/ -l POSTGRES_logfile start; -echo "> Conecting as admin user: " + ${USER}; -~/pg/postgres/bin/psql -U ${USER} postgres; +#echo "> Conecting as admin user: " + ${USER}; +#~/pg/postgres/bin/psql -U ${USER} postgres; diff --git a/src/db/initPostgresDB.ts b/src/db/initPostgresDB.ts new file mode 100644 index 0000000..307d9b6 --- /dev/null +++ b/src/db/initPostgresDB.ts @@ -0,0 +1,13 @@ +var Sequelize = require('sequelize'); +const Op = Sequelize.Op; +const gres = new Sequelize('postgres://admin:eprprJacR0hBpmWvs5IDJZTnjRAY2gM3tSm0b1af@localhost:5432/be4', + {operatorsAliases : false}); + +gres + .authenticate() + .then(() => { + console.log('Connection has been established successfully.'); + }) + .catch(err => { + console.error('Unable to connect to the database:', err); + }); diff --git a/tsconfig.json b/tsconfig.json index 2da3eed..745ef12 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -3,7 +3,7 @@ /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', or 'ESNEXT'. */ "target": "es6", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */ - "module": "commonjs", + "module": "commonjs", /* Where to output .js files */ "outDir": "dist" }, @@ -14,5 +14,7 @@ /* Exclude directory */ "exclude": [ "node_modules" - ] -}
\ No newline at end of file + ], + "experimentalDecorators": true, + "emitDecoratorMetadata": true +} |
