From 1947515dd9182bc1cf06a72e76ccd4bd26146002 Mon Sep 17 00:00:00 2001 From: Maciej Rapacz Date: Mon, 16 Oct 2017 17:24:31 +0200 Subject: [PATCH] enhancement(fixtures): Add option for room seeding (#129) --- Makefile | 15 ++++++++++++--- fixtures/main.py | 28 +++++++++++++++++++--------- scripts/populate_database | 1 - 3 files changed, 31 insertions(+), 13 deletions(-) delete mode 100755 scripts/populate_database diff --git a/Makefile b/Makefile index c783ec1..3ba8952 100644 --- a/Makefile +++ b/Makefile @@ -62,9 +62,18 @@ local-db: ## Create and migrate db locally local-deps: ## Download all needed dependencies cd aion && mix deps.get && npm install && cd web/elm && elm-package install -y -local-config: ## Switch config file to +local-config: ## Switch config file to the one containing settings for local use cp aion/config/local_dev.exs aion/config/dev.exs + cp fixtures/src/local_config.py fixtures/src/config.py + +################################## +## ~> DATABASE SEEDING PART <~ ## +################################## populate-database: ## Seed database with fixtures prepared in fixtures/jpks/ - cp fixtures/src/local_config.py fixtures/src/config.py - scripts/populate_database +populate-database: local-config + cd fixtures && python3 main.py + +populate-rooms: ## Create a set of rooms aggregating all the questions present in the database +populate-rooms: local-config + cd fixtures && python3 main.py --rooms diff --git a/fixtures/main.py b/fixtures/main.py index d18ed0b..99a2a24 100644 --- a/fixtures/main.py +++ b/fixtures/main.py @@ -5,14 +5,11 @@ from src.connect_to_db import connect_to_db -if __name__ == '__main__': - parser = argparse.ArgumentParser(description='Dump questions in postgresql database.') - parser.add_argument('-path', type=str, nargs='*', - help="Provide path to file/folder containing questions in a proper format") - args = parser.parse_args() - paths = args.path - conn = connect_to_db() +def create_rooms(conn): + # populate_one_category_rooms(conn) + populate_all_categories_rooms(conn) +def seed_database(conn, paths): if paths is None: paths = ['example/'] @@ -20,5 +17,18 @@ questions = get_questions(path) load_questions(questions, conn) - # populate_one_category_rooms(conn) - # populate_all_categories_rooms(conn) + + +if __name__ == '__main__': + parser = argparse.ArgumentParser(description='Load questions into postgresql database.') + parser.add_argument('-path', type=str, nargs='*', + help="Provide path to file/folder containing questions in a proper format") + parser.add_argument('--rooms', action='store_true') + args = parser.parse_args() + + conn = connect_to_db() + + if args.rooms: + create_rooms(conn) + else: + seed_database(conn, args.path) diff --git a/scripts/populate_database b/scripts/populate_database deleted file mode 100755 index a934b32..0000000 --- a/scripts/populate_database +++ /dev/null @@ -1 +0,0 @@ -python3 fixtures/main.py -path fixtures/jpks/