From 5168cba8e4ccfb8a1c348c80706b2e7a987bb152 Mon Sep 17 00:00:00 2001 From: Yuichi Nakai Date: Sat, 30 Aug 2025 03:30:03 +0900 Subject: [PATCH] feat(db): support postgresql database (#3643) Co-authored-by: Meier Lukas --- .env.example | 4 + ...migration_postgresql_generate.run copy.xml | 13 + development/development.docker-compose.yml | 26 +- package.json | 2 + packages/db/collection.ts | 32 +- packages/db/configs/postgresql.config.ts | 20 + packages/db/driver.ts | 39 +- packages/db/env.ts | 5 +- packages/db/index.ts | 2 +- .../db/migrations/postgresql/0000_initial.sql | 322 +++ .../postgresql/meta/0000_snapshot.json | 1991 +++++++++++++++++ .../migrations/postgresql/meta/_journal.json | 13 + packages/db/migrations/postgresql/migrate.ts | 45 + packages/db/migrations/seed.ts | 3 +- packages/db/package.json | 10 +- packages/db/schema/index.ts | 11 +- packages/db/schema/mysql.ts | 1 + packages/db/schema/postgresql.ts | 775 +++++++ packages/db/test/postgresql-migration.spec.ts | 46 + packages/db/test/schema.spec.ts | 123 +- packages/db/transactions.ts | 17 +- pnpm-lock.yaml | 135 +- 22 files changed, 3603 insertions(+), 32 deletions(-) create mode 100644 .run/db_migration_postgresql_generate.run copy.xml create mode 100644 packages/db/configs/postgresql.config.ts create mode 100644 packages/db/migrations/postgresql/0000_initial.sql create mode 100644 packages/db/migrations/postgresql/meta/0000_snapshot.json create mode 100644 packages/db/migrations/postgresql/meta/_journal.json create mode 100644 packages/db/migrations/postgresql/migrate.ts create mode 100644 packages/db/schema/postgresql.ts create mode 100644 packages/db/test/postgresql-migration.spec.ts diff --git a/.env.example b/.env.example index 28fa9d4de..d643c1194 100644 --- a/.env.example +++ b/.env.example @@ -34,6 +34,10 @@ DB_URL='FULL_PATH_TO_YOUR_SQLITE_DB_FILE' # DB_PASSWORD='password' # DB_NAME='name-of-database' +# The following is an example on how to use the node-postgres driver: +# DB_DRIVER='node-postgres' +# DB_URL='postgres://user:password@host:port/database' + # The below path can be used to store trusted certificates, it is not required and can be left empty. # If it is empty, it will default to `/appdata/trusted-certificates` in production. # If it is used, please use the full path to the directory where the certificates are stored. diff --git a/.run/db_migration_postgresql_generate.run copy.xml b/.run/db_migration_postgresql_generate.run copy.xml new file mode 100644 index 000000000..4bc02bdba --- /dev/null +++ b/.run/db_migration_postgresql_generate.run copy.xml @@ -0,0 +1,13 @@ + + + + + +