AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.
feat(rnd): Add postgres schema check on linting step + auto gen migration and schema sync command (poetry run schema) (#7667)
Zamil Majdyc9d41e69bd61
diff --git a/rnd/autogpt_server/linter.py b/rnd/autogpt_server/linter.pyindex 83c574b034..5127b377a5 100644--- a/rnd/autogpt_server/linter.py+++ b/rnd/autogpt_server/linter.py@@ -1,4 +1,5 @@import os+import reimport subprocessdirectory = 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}")diff --git a/rnd/autogpt_server/postgres/schema.prisma b/rnd/autogpt_server/postgres/schema.prismaindex 9c36e220d0..6140fd060b 100644--- a/rnd/autogpt_server/postgres/schema.prisma+++ b/rnd/autogpt_server/postgres/schema.prisma@@ -1,3 +1,4 @@+// THIS FILE IS AUTO-GENERATED, RUN `poetry run schema` TO UPDATEdatasource db {provider = "postgresql"url = env("DATABASE_URL")diff --git a/rnd/autogpt_server/pyproject.toml b/rnd/autogpt_server/pyproject.tomlindex f996cc5c81..8fa8202af6 100644--- a/rnd/autogpt_server/pyproject.toml+++ b/rnd/autogpt_server/pyproject.toml@@ -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]diff --git a/rnd/autogpt_server/schema.prisma b/rnd/autogpt_server/schema.prismaindex ce5ab6ad94..e8ba5ec4b1 100644--- a/rnd/autogpt_server/schema.prisma+++ b/rnd/autogpt_server/schema.prisma@@ -65,7 +65,7 @@ model AgentNodeLink {agentNodeSinkId StringAgentNodeSink 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)}