SlangLab-NU / VoiceCollector

Apache License 2.0
1 stars 0 forks source link

23 ephemeral database tables vs permanent ones #24

Closed jordan-git-lewis closed 1 year ago

jordan-git-lewis commented 1 year ago

write_references_to_db() has been moved to init.py so references should be updated at time of app initialization. Then write_references_to_db() has an extra line that deletes all reference table content and then rewrites. This might be inefficient, but we dont have many references, so the execution is relatively quick

macarious commented 1 year ago

I ran it and it works as intended.

However, when database.db is not created beforehand from running init_db.py, an error would occur. If the database.db does not exist, can we either catch and return an error message, or automatically creates a database.db by running init_db.py?

Here is the error when database.db does not already exist when running flask run --debug:

(voice-collector) C:\Users\macar\Documents\SlangLab-NU\VoiceCollector\server\app>flask run --debug
Traceback (most recent call last):
  File "C:\Users\macar\anaconda3\envs\voice-collector\lib\runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Users\macar\anaconda3\envs\voice-collector\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "C:\Users\macar\anaconda3\envs\voice-collector\Scripts\flask.exe\__main__.py", line 7, in <module>
  File "c:\users\macar\anaconda3\envs\voice-collector\lib\site-packages\flask\cli.py", line 1050, in main
    cli.main()
  File "c:\users\macar\anaconda3\envs\voice-collector\lib\site-packages\click\core.py", line 1078, in main
    rv = self.invoke(ctx)
  File "c:\users\macar\anaconda3\envs\voice-collector\lib\site-packages\click\core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "c:\users\macar\anaconda3\envs\voice-collector\lib\site-packages\click\core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "c:\users\macar\anaconda3\envs\voice-collector\lib\site-packages\click\core.py", line 783, in invoke
    return __callback(*args, **kwargs)
  File "c:\users\macar\anaconda3\envs\voice-collector\lib\site-packages\click\decorators.py", line 92, in new_func
    return ctx.invoke(f, obj, *args, **kwargs)
  File "c:\users\macar\anaconda3\envs\voice-collector\lib\site-packages\click\core.py", line 783, in invoke
    return __callback(*args, **kwargs)
  File "c:\users\macar\anaconda3\envs\voice-collector\lib\site-packages\flask\cli.py", line 911, in run_command
    raise e from None
  File "c:\users\macar\anaconda3\envs\voice-collector\lib\site-packages\flask\cli.py", line 897, in run_command
    app = info.load_app()
  File "c:\users\macar\anaconda3\envs\voice-collector\lib\site-packages\flask\cli.py", line 308, in load_app
    app = locate_app(import_name, name)
  File "c:\users\macar\anaconda3\envs\voice-collector\lib\site-packages\flask\cli.py", line 218, in locate_app
    __import__(module_name)
  File "C:\Users\macar\Documents\SlangLab-NU\VoiceCollector\server\app\__init__.py", line 22, in <module>
    db_helper.write_references_to_db()
  File "C:\Users\macar\Documents\SlangLab-NU\VoiceCollector\server\app\scripts\db_helper.py", line 117, in write_references_to_db      
    cursor.execute("DELETE FROM reference;")
sqlite3.OperationalError: no such table: reference