mirror of
https://github.com/Significant-Gravitas/AutoGPT.git
synced 2026-04-08 03:00:28 -04:00
feat(rnd): Add postgres schema check on linting step + auto gen migration and schema sync command (poetry run schema) (#7667)
### Background
Migration not being synced has caused issues and CI is not catching this yet.
### Changes 🏗️
* Added schema check in both sqlite & postgres prisma.schema on linting step.
* Introduced `poetry run schema` for syncing prisma.schema + generating migration in both files.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import os
|
||||
import re
|
||||
import subprocess
|
||||
|
||||
directory = os.path.dirname(os.path.realpath(__file__))
|
||||
@@ -19,9 +20,43 @@ def lint():
|
||||
print("Lint failed, try running `poetry run format` to fix the issues: ", e)
|
||||
raise e
|
||||
|
||||
try:
|
||||
run("schema_lint")
|
||||
except subprocess.CalledProcessError as e:
|
||||
print("Lint failed, try running `poetry run schema` to fix the issues: ", e)
|
||||
raise e
|
||||
|
||||
|
||||
def format():
|
||||
run("ruff", "check", "--fix", ".")
|
||||
run("isort", "--profile", "black", ".")
|
||||
run("black", ".")
|
||||
run("pyright", ".")
|
||||
|
||||
|
||||
def schema():
|
||||
file = os.path.join(directory, "schema.prisma")
|
||||
text = open(file, "r").read()
|
||||
text = re.sub(r'provider\s+=\s+".*"', 'provider = "postgresql"', text, 1)
|
||||
text = re.sub(r'url\s+=\s+".*"', 'url = env("DATABASE_URL")', text, 1)
|
||||
text = "// THIS FILE IS AUTO-GENERATED, RUN `poetry run schema` TO UPDATE\n" + text
|
||||
with open(os.path.join(directory, "postgres", "schema.prisma"), "w") as f:
|
||||
f.write(text)
|
||||
|
||||
run("prisma", "format", "--schema", "schema.prisma")
|
||||
run("prisma", "format", "--schema", "postgres/schema.prisma")
|
||||
run("prisma", "migrate", "dev", "--schema", "schema.prisma")
|
||||
run("prisma", "migrate", "dev", "--schema", "postgres/schema.prisma")
|
||||
|
||||
|
||||
def schema_lint():
|
||||
def read_schema(path: str) -> list[str]:
|
||||
with open(path, "r") as f:
|
||||
return [v for v in f.read().splitlines() if not v.startswith("//")]
|
||||
|
||||
sqlite_schema = read_schema(os.path.join(directory, "schema.prisma"))
|
||||
postgres_schema = read_schema(os.path.join(directory, "postgres", "schema.prisma"))
|
||||
diff = [line.strip() for line in set(sqlite_schema) ^ set(postgres_schema)]
|
||||
|
||||
if line := next((v for v in diff if not v.startswith(("provider", "url"))), None):
|
||||
raise Exception(f"schema.prisma & postgres/schema.prisma mismatch: {line}")
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// THIS FILE IS AUTO-GENERATED, RUN `poetry run schema` TO UPDATE
|
||||
datasource db {
|
||||
provider = "postgresql"
|
||||
url = env("DATABASE_URL")
|
||||
|
||||
@@ -61,6 +61,8 @@ app = "autogpt_server.app:main"
|
||||
cli = "autogpt_server.cli:main"
|
||||
format = "linter:format"
|
||||
lint = "linter:lint"
|
||||
schema = "linter:schema"
|
||||
schema_lint = "linter:schema_lint"
|
||||
|
||||
# https://poethepoet.natn.io/index.html
|
||||
[tool.poe]
|
||||
|
||||
@@ -65,7 +65,7 @@ model AgentNodeLink {
|
||||
agentNodeSinkId String
|
||||
AgentNodeSink AgentNode @relation("AgentNodeSink", fields: [agentNodeSinkId], references: [id])
|
||||
sinkName String
|
||||
|
||||
|
||||
// Default: the data coming from the source can only be consumed by the sink once, Static: input data will be reused.
|
||||
isStatic Boolean @default(false)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user