-
-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
151 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
init-migrations: | ||
aerich init -t src.portr_admin.db.TORTOISE_ORM | ||
|
||
init-db: | ||
aerich init-db | ||
|
||
create-migrations: | ||
aerich migrate --name $(name) | ||
|
||
run-migrations: | ||
aerich upgrade |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
from tortoise import BaseDBAsyncClient | ||
|
||
|
||
async def upgrade(db: BaseDBAsyncClient) -> str: | ||
return """ | ||
CREATE TABLE IF NOT EXISTS "aerich" ( | ||
"id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, | ||
"version" VARCHAR(255) NOT NULL, | ||
"app" VARCHAR(100) NOT NULL, | ||
"content" JSON NOT NULL | ||
); | ||
CREATE TABLE IF NOT EXISTS "user" ( | ||
"id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, | ||
"created_at" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
"updated_at" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
"email" VARCHAR(255) NOT NULL UNIQUE, | ||
"first_name" VARCHAR(255), | ||
"last_name" VARCHAR(255), | ||
"is_superuser" INT NOT NULL DEFAULT 0 | ||
); | ||
CREATE TABLE IF NOT EXISTS "session" ( | ||
"id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, | ||
"created_at" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
"updated_at" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
"token" VARCHAR(255) NOT NULL UNIQUE, | ||
"expires_at" TIMESTAMP NOT NULL, | ||
"user_id" INT NOT NULL REFERENCES "user" ("id") ON DELETE CASCADE | ||
); | ||
CREATE INDEX IF NOT EXISTS "idx_session_expires_823c67" ON "session" ("expires_at"); | ||
CREATE TABLE IF NOT EXISTS "githubuser" ( | ||
"id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, | ||
"github_id" BIGINT NOT NULL UNIQUE, | ||
"github_access_token" VARCHAR(255) NOT NULL, | ||
"github_avatar_url" VARCHAR(255) NOT NULL, | ||
"user_id" INT NOT NULL UNIQUE REFERENCES "user" ("id") ON DELETE CASCADE | ||
); | ||
CREATE INDEX IF NOT EXISTS "idx_githubuser_github__f7df59" ON "githubuser" ("github_id"); | ||
CREATE TABLE IF NOT EXISTS "team" ( | ||
"id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, | ||
"created_at" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
"updated_at" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
"name" VARCHAR(255) NOT NULL UNIQUE, | ||
"slug" VARCHAR(255) NOT NULL UNIQUE | ||
); | ||
CREATE INDEX IF NOT EXISTS "idx_team_slug_b2d3a8" ON "team" ("slug"); | ||
CREATE TABLE IF NOT EXISTS "team_users" ( | ||
"id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, | ||
"created_at" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
"updated_at" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
"secret_key" VARCHAR(42) NOT NULL UNIQUE, | ||
"role" VARCHAR(255) NOT NULL DEFAULT 'member', | ||
"team_id" INT NOT NULL REFERENCES "team" ("id") ON DELETE CASCADE, | ||
"user_id" INT NOT NULL REFERENCES "user" ("id") ON DELETE CASCADE | ||
); | ||
CREATE INDEX IF NOT EXISTS "idx_team_users_secret__22c341" ON "team_users" ("secret_key"); | ||
CREATE TABLE IF NOT EXISTS "instancesettings" ( | ||
"id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, | ||
"created_at" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
"updated_at" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
"smtp_enabled" INT NOT NULL DEFAULT 0, | ||
"smtp_host" VARCHAR(255), | ||
"smtp_port" INT, | ||
"smtp_username" VARCHAR(255), | ||
"smtp_password" BLOB, | ||
"from_address" VARCHAR(255), | ||
"add_user_email_subject" VARCHAR(255), | ||
"add_user_email_body" TEXT, | ||
"updated_by_id" INT REFERENCES "user" ("id") ON DELETE SET NULL | ||
); | ||
CREATE TABLE IF NOT EXISTS "connection" ( | ||
"created_at" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
"updated_at" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
"id" VARCHAR(26) NOT NULL PRIMARY KEY, | ||
"type" VARCHAR(255) NOT NULL, | ||
"subdomain" VARCHAR(255), | ||
"port" INT, | ||
"status" VARCHAR(255) NOT NULL DEFAULT 'reserved', | ||
"started_at" TIMESTAMP, | ||
"closed_at" TIMESTAMP, | ||
"created_by_id" INT NOT NULL REFERENCES "team_users" ("id") ON DELETE CASCADE, | ||
"team_id" INT NOT NULL REFERENCES "team" ("id") ON DELETE CASCADE | ||
); | ||
CREATE INDEX IF NOT EXISTS "idx_connection_status_7d03b9" ON "connection" ("status");""" | ||
|
||
|
||
async def downgrade(db: BaseDBAsyncClient) -> str: | ||
return """ | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,27 @@ | ||
import asyncio | ||
from aerich import Command # type: ignore | ||
|
||
|
||
from portr_admin.db import connect_db, disconnect_db | ||
from portr_admin.db import TORTOISE_ORM, connect_db, disconnect_db | ||
from portr_admin.services.settings import populate_instance_settings | ||
|
||
|
||
async def main(): | ||
await connect_db(generate_schemas=True) | ||
command = Command(tortoise_config=TORTOISE_ORM) | ||
|
||
|
||
async def run_migrations(): | ||
await command.init() | ||
await command.upgrade(run_in_transaction=True) | ||
|
||
|
||
async def populate_settings(): | ||
await connect_db() | ||
await populate_instance_settings() | ||
await disconnect_db() | ||
|
||
|
||
async def main(): | ||
await run_migrations() | ||
await populate_settings() | ||
|
||
|
||
asyncio.run(main()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters