Skip to content

Commit

Permalink
enhancement(fixtures): Add option for room seeding (#129)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrapacz authored Oct 16, 2017
1 parent 5abb16e commit 1947515
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 13 deletions.
15 changes: 12 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
28 changes: 19 additions & 9 deletions fixtures/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,30 @@
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/']

for path in paths:
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)
1 change: 0 additions & 1 deletion scripts/populate_database

This file was deleted.

0 comments on commit 1947515

Please sign in to comment.