Skip to content

Provide poetry based script to initialise the database #24

Closed
@devraj

Description

@devraj

While initialising my first project from the template I had to do the following to initialise the database using the following steps:

root@af3b478425ca:/opt# python
Python 3.10.4 (main, May 11 2022, 10:32:02) [GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from acacia import db, models
>>> db.init_models()
<coroutine object init_models at 0xffff993e5a10>
>>> init = db.init_models()
>>> init()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'coroutine' object is not callable
>>> import asyncio
>>> asyncio.run(init)
2022-07-23 01:35:04,927 INFO sqlalchemy.engine.Engine select pg_catalog.version()
2022-07-23 01:35:04,927 INFO sqlalchemy.engine.Engine [raw sql] ()
2022-07-23 01:35:04,928 INFO sqlalchemy.engine.Engine select current_schema()
2022-07-23 01:35:04,928 INFO sqlalchemy.engine.Engine [raw sql] ()
2022-07-23 01:35:04,929 INFO sqlalchemy.engine.Engine show standard_conforming_strings
2022-07-23 01:35:04,929 INFO sqlalchemy.engine.Engine [raw sql] ()
2022-07-23 01:35:04,930 INFO sqlalchemy.engine.Engine BEGIN (implicit)
2022-07-23 01:35:04,931 INFO sqlalchemy.engine.Engine select relname from pg_class c join pg_namespace n on n.oid=c.relnamespace where pg_catalog.pg_table_is_visible(c.oid) and relname=%s
2022-07-23 01:35:04,931 INFO sqlalchemy.engine.Engine [generated in 0.00014s] ('user',)
2022-07-23 01:35:04,932 INFO sqlalchemy.engine.Engine select relname from pg_class c join pg_namespace n on n.oid=c.relnamespace where pg_catalog.pg_table_is_visible(c.oid) and relname=%s
2022-07-23 01:35:04,932 INFO sqlalchemy.engine.Engine [cached since 0.001741s ago] ('user',)
2022-07-23 01:35:04,933 INFO sqlalchemy.engine.Engine 
CREATE TABLE "user" (
	id UUID DEFAULT gen_random_uuid() NOT NULL, 
	created_at TIMESTAMP WITH TIME ZONE DEFAULT now() NOT NULL, 
	updated_at TIMESTAMP WITH TIME ZONE DEFAULT now() NOT NULL, 
	email VARCHAR, 
	password VARCHAR, 
	verified BOOLEAN DEFAULT false NOT NULL, 
	mobile_number VARCHAR, 
	first_name VARCHAR, 
	last_name VARCHAR, 
	is_admin BOOLEAN DEFAULT false NOT NULL, 
	otp_secret VARCHAR, 
	PRIMARY KEY (id), 
	UNIQUE (email)
)


2022-07-23 01:35:04,933 INFO sqlalchemy.engine.Engine [no key 0.00007s] ()
2022-07-23 01:35:04,939 INFO sqlalchemy.engine.Engine COMMIT

which was essentially me running the init_db async method to create the tables. It would be preferable to wrap this up into a poetry script and made available as a task, so the user could do something

task db:init

and the initial database schema would be present. This would go hand in hand with #23 and could possible combine the two steps.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions