From a8faabddc36fb1f0ac419f4f749c454cecee52fa Mon Sep 17 00:00:00 2001 From: SamR1 Date: Sun, 7 Jan 2018 18:11:19 +0100 Subject: [PATCH] API: use of PostgreSQL instead of MySQL API: use of PostgreSQL instead of MySQL --- Makefile | 1 + Makefile.config | 2 ++ docs/db/mpwo.sql | 6 ------ mpwo_api/db/mpwo.sql | 5 +++++ mpwo_api/mpwo_api/config.py | 4 ++-- mpwo_api/requirements.txt | 1 + 6 files changed, 11 insertions(+), 8 deletions(-) delete mode 100644 docs/db/mpwo.sql create mode 100644 mpwo_api/db/mpwo.sql diff --git a/Makefile b/Makefile index 48554da8..a49b35a1 100644 --- a/Makefile +++ b/Makefile @@ -15,6 +15,7 @@ install-client: $(NPM) install install-python: + test -d $(VENV) || virtualenv $(VENV) -p $(PYTHON_VERSION) $(PIP) install -r $(REQUIREMENTS) serve-python: diff --git a/Makefile.config b/Makefile.config index 722b3373..a5571b42 100644 --- a/Makefile.config +++ b/Makefile.config @@ -6,6 +6,8 @@ export REACT_APP_API_URL ?= http://$(HOST):$(API_PORT)/api/ export FLASK_APP ?= $(PWD)/mpwo_api/server.py export TEST_URL ?= http://$(HOST):$(CLIENT_PORT) export REQUIREMENTS ?= $(PWD)/mpwo_api/requirements.txt +export DATABASE_URL ?= postgres://mpwo:mpwo@$(HOST):5432/mpwo +export DATABASE_TEST_URL ?= postgres://mpwo:mpwo@$(HOST):5432/mpwo_test # Python env PYTHON_VERSION ?= python diff --git a/docs/db/mpwo.sql b/docs/db/mpwo.sql deleted file mode 100644 index 07265778..00000000 --- a/docs/db/mpwo.sql +++ /dev/null @@ -1,6 +0,0 @@ -CREATE DATABASE IF NOT EXISTS mpwo CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; -CREATE DATABASE IF NOT EXISTS mpwo_test CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; -CREATE USER 'mpwo'@'localhost' IDENTIFIED BY 'mpwo'; -GRANT ALL PRIVILEGES ON `mpwo` . * TO 'mpwo'@'localhost'; -GRANT ALL PRIVILEGES ON `mpwo_dev` . * TO 'mpwo'@'localhost'; -FLUSH PRIVILEGES; \ No newline at end of file diff --git a/mpwo_api/db/mpwo.sql b/mpwo_api/db/mpwo.sql new file mode 100644 index 00000000..b35d7b9a --- /dev/null +++ b/mpwo_api/db/mpwo.sql @@ -0,0 +1,5 @@ +CREATE DATABASE mpwo; +CREATE DATABASE mpwo_test; +CREATE USER mpwo WITH PASSWORD 'mpwo'; +GRANT ALL PRIVILEGES ON DATABASE mpwo TO mpwo; +GRANT ALL PRIVILEGES ON DATABASE mpwo_test TO mpwo; diff --git a/mpwo_api/mpwo_api/config.py b/mpwo_api/mpwo_api/config.py index f9828ab9..fa55ee9a 100644 --- a/mpwo_api/mpwo_api/config.py +++ b/mpwo_api/mpwo_api/config.py @@ -20,7 +20,7 @@ class DevelopmentConfig(BaseConfig): """Development configuration""" DEBUG = True SQLALCHEMY_DATABASE_URI = \ - 'mysql+mysqldb://mpwo:mpwo@127.0.0.1:3306/mpwo' + os.environ.get('DATABASE_URL') SECRET_KEY = 'development key' USERNAME = 'admin' PASSWORD = 'default' @@ -31,7 +31,7 @@ class TestingConfig(BaseConfig): """Development configuration""" DEBUG = True SQLALCHEMY_DATABASE_URI = \ - 'mysql+mysqldb://mpwo:mpwo@127.0.0.1:3306/mpwo_test' + os.environ.get('DATABASE_TEST_URL') SECRET_KEY = 'test key' USERNAME = 'admin' PASSWORD = 'default' diff --git a/mpwo_api/requirements.txt b/mpwo_api/requirements.txt index 465e1522..901e92e0 100644 --- a/mpwo_api/requirements.txt +++ b/mpwo_api/requirements.txt @@ -14,6 +14,7 @@ Jinja2==2.10 MarkupSafe==1.0 mccabe==0.6.1 mysqlclient==1.3.12 +psycopg2==2.7.3.2 pycodestyle==2.3.1 pycparser==2.18 pyflakes==1.6.0