Skip to content

Commit

Permalink
feat(init): update deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
wangxin688 committed Jan 19, 2024
1 parent 8f51518 commit 911529e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
29 changes: 27 additions & 2 deletions deploy/init_pg.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,40 @@

from sqlalchemy import text

from src.auth.models import Group, Role, User
from src.db.session import async_session
from src.enums import ReservedRoleSlug


async def create_pg_extensions() -> None:
async with async_session() as session:
await session.execute(text('create EXTENSION if not EXISTS "pgcrypto"'))
await session.execute(text('create EXTENSION if not EXISTS "hstore"'))
await session.commit()


async def create_init_user() -> None:
async with async_session() as session:
new_role = Role(name="Administrator", slug=ReservedRoleSlug.ADMIN, description="App system admin")
session.add(new_role)
await session.commit()
new_group = Group(
name="System Administrator",
description="App systemic administrators group",
role_id=new_role.id,
user=[
User(
name="Administrator",
email="admin@system.com",
password="admin", # noqa: S106
role_id=new_role.id,
)
],
)
session.add(new_group)
await session.commit()


if __name__ == "__main__":
asyncio.run(create_pg_extensions())


asyncio.run(create_init_user())
2 changes: 1 addition & 1 deletion src/auth/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class User(Base, AuditTimeMixin):
group: Mapped["Group"] = relationship(back_populates="user", passive_deletes=True)
role_id: Mapped[int] = mapped_column(ForeignKey(Role.id, ondelete="CASCADE"))
role: Mapped["Role"] = relationship(backref="user", passive_deletes=True)
auth_info: Mapped[dict] = mapped_column(MutableDict.as_mutable(JSON))
auth_info: Mapped[dict | None] = mapped_column(MutableDict.as_mutable(JSON))


Group.user_count = column_property(
Expand Down

0 comments on commit 911529e

Please sign in to comment.