Closed banjtheman closed 3 years ago
Hi, I can give this a shot.
@banjtheman is CreateDB.sql
required to be executed to pre-seed the database?
edit: I'm getting an error on the curl command...
postgres_1 | ERROR: relation "states" does not exist at character 219
postgres_1 | STATEMENT: SELECT states.id AS states_id, states.state AS states_state, states.county AS states_county, states.year AS states_year, states.item AS states_item, states.budget AS states_budget, states.source AS states_source
postgres_1 | FROM states
postgres_1 | WHERE states.state IS NULL AND states.county = 'Arlingtion'
api_1 | [2020-10-05 22:15:30,828] ERROR in app: Exception on /getdata [GET]
api_1 | Traceback (most recent call last):
api_1 | File "/usr/local/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1276, in _execute_context
api_1 | self.dialect.do_execute(
api_1 | File "/usr/local/lib/python3.8/site-packages/sqlalchemy/engine/default.py", line 593, in do_execute
api_1 | cursor.execute(statement, parameters)
api_1 | psycopg2.errors.UndefinedTable: relation "states" does not exist
api_1 | LINE 2: FROM states
api_1 | ^
api_1 |
api_1 |
api_1 | The above exception was the direct cause of the following exception:
api_1 |
api_1 | Traceback (most recent call last):
api_1 | File "/usr/local/lib/python3.8/site-packages/flask/app.py", line 2447, in wsgi_app
api_1 | response = self.full_dispatch_request()
api_1 | File "/usr/local/lib/python3.8/site-packages/flask/app.py", line 1952, in full_dispatch_request
api_1 | rv = self.handle_user_exception(e)
api_1 | File "/usr/local/lib/python3.8/site-packages/flask/app.py", line 1821, in handle_user_exception
api_1 | reraise(exc_type, exc_value, tb)
api_1 | File "/usr/local/lib/python3.8/site-packages/flask/_compat.py", line 39, in reraise
api_1 | raise value
api_1 | File "/usr/local/lib/python3.8/site-packages/flask/app.py", line 1950, in full_dispatch_request
api_1 | rv = self.dispatch_request()
api_1 | File "/usr/local/lib/python3.8/site-packages/flask/app.py", line 1936, in dispatch_request
api_1 | return self.view_functions[rule.endpoint](**req.view_args)
api_1 | File "/app/api/budgetsdata.py", line 123, in getdata
api_1 | for i in data:
api_1 | File "/usr/local/lib/python3.8/site-packages/sqlalchemy/orm/query.py", line 3508, in __iter__
api_1 | return self._execute_and_instances(context)
api_1 | File "/usr/local/lib/python3.8/site-packages/sqlalchemy/orm/query.py", line 3533, in _execute_and_instances
api_1 | result = conn.execute(querycontext.statement, self._params)
api_1 | File "/usr/local/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1011, in execute
api_1 | return meth(self, multiparams, params)
api_1 | File "/usr/local/lib/python3.8/site-packages/sqlalchemy/sql/elements.py", line 298, in _execute_on_connection
api_1 | return connection._execute_clauseelement(self, multiparams, params)
api_1 | File "/usr/local/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1124, in _execute_clauseelement
api_1 | ret = self._execute_context(
api_1 | File "/usr/local/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1316, in _execute_context
api_1 | self._handle_dbapi_exception(
api_1 | File "/usr/local/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1510, in _handle_dbapi_exception
api_1 | util.raise_(
api_1 | File "/usr/local/lib/python3.8/site-packages/sqlalchemy/util/compat.py", line 182, in raise_
api_1 | raise exception
api_1 | File "/usr/local/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1276, in _execute_context
api_1 | self.dialect.do_execute(
api_1 | File "/usr/local/lib/python3.8/site-packages/sqlalchemy/engine/default.py", line 593, in do_execute
api_1 | cursor.execute(statement, parameters)
api_1 | sqlalchemy.exc.ProgrammingError: (psycopg2.errors.UndefinedTable) relation "states" does not exist
api_1 | LINE 2: FROM states
api_1 | ^
api_1 |
api_1 | [SQL: SELECT states.id AS states_id, states.state AS states_state, states.county AS states_county, states.year AS states_year, states.item AS states_item, states.budget AS states_budget, states.source AS states_source
api_1 | FROM states
api_1 | WHERE states.state IS NULL AND states.county = %(county_1)s]
api_1 | [parameters: {'county_1': 'Arlingtion'}]
api_1 | (Background on this error at: http://sqlalche.me/e/13/f405)
is CreateDB.sql required to be executed to pre-seed the database?
Yes the goal would be for the setup script to pre seed the database
The commands I posted in definetion of done should work after you have completed the task
If the API not working with the database schema, I'll make a new issue to fix the bug.
so the createsql.db
file doesn't create the states
table and seed it with the data, I created a PR. LMK your thoughts.
What is the Task
We want to have two docker-compose files that consist of the following
docker-compose.yml
docker-compose-api.yml
The API should connect to the postgress database, so we can query it.
Why do we want to do this
To seperate out the applications
How can I get started?
Create docker-compose-api.yml
add the services to this file
Update the paramters to match
Remove api from docker-compose.yml
Leave any questions you have in the comments
Definition of Done
can run the following...