appos 0.3.4-0 → 0.3.5-0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin/main.mjs +449 -241
- package/dist/exports/api/database.d.mts +5 -3
- package/dist/exports/api/database.mjs +5 -4
- package/dist/exports/api/workflows/api/database.d.mts +4 -3
- package/dist/exports/cli/api/database.d.mts +4 -3
- package/dist/exports/tests/api/database.d.mts +5 -3
- package/dist/exports/tests/api/database.mjs +1 -1
- package/package.json +1 -1
|
@@ -3,10 +3,12 @@ import * as drizzle_orm22 from "drizzle-orm";
|
|
|
3
3
|
import { AnyRelations, EmptyRelations } from "drizzle-orm";
|
|
4
4
|
import { PgTable } from "drizzle-orm/pg-core";
|
|
5
5
|
import * as drizzle_orm_node_postgres0 from "drizzle-orm/node-postgres";
|
|
6
|
-
import
|
|
6
|
+
import * as pg0 from "pg";
|
|
7
|
+
import pg from "pg";
|
|
7
8
|
import { MigrationConfig } from "drizzle-orm/migrator";
|
|
8
9
|
|
|
9
10
|
//#region src/api/database.d.ts
|
|
11
|
+
type PoolConfig = pg.PoolConfig;
|
|
10
12
|
/**
|
|
11
13
|
* Extract qualified table names from db object.
|
|
12
14
|
*/
|
|
@@ -69,7 +71,7 @@ declare function dbChanges<T extends PgTable>(table: T): {
|
|
|
69
71
|
* @returns The defined database instance.
|
|
70
72
|
*/
|
|
71
73
|
declare function defineDatabase<TSchema extends Record<string, unknown> = Record<string, never>, TRelations extends AnyRelations = EmptyRelations>(opts: DefineDatabaseOptions<TSchema, TRelations>): Promise<drizzle_orm_node_postgres0.NodePgDatabase<TSchema, TRelations> & {
|
|
72
|
-
$client: Pool;
|
|
74
|
+
$client: pg0.Pool;
|
|
73
75
|
}>;
|
|
74
76
|
/**
|
|
75
77
|
* Options for defining a test database.
|
|
@@ -91,7 +93,7 @@ interface DefineTestDatabaseOptions<TSchema extends Record<string, unknown> = Re
|
|
|
91
93
|
declare function defineTestDatabase<TSchema extends Record<string, unknown> = Record<string, never>, TRelations extends AnyRelations = EmptyRelations>(opts: DefineTestDatabaseOptions<TSchema, TRelations>): Promise<{
|
|
92
94
|
cleanUp: () => Promise<void>;
|
|
93
95
|
db: drizzle_orm_node_postgres0.NodePgDatabase<TSchema, TRelations> & {
|
|
94
|
-
$client: Pool;
|
|
96
|
+
$client: pg0.Pool;
|
|
95
97
|
};
|
|
96
98
|
dbName: string;
|
|
97
99
|
}>;
|
|
@@ -3,9 +3,10 @@ import { getTableName, sql } from "drizzle-orm";
|
|
|
3
3
|
import { join } from "node:path";
|
|
4
4
|
import { drizzle } from "drizzle-orm/node-postgres";
|
|
5
5
|
import { migrate } from "drizzle-orm/node-postgres/migrator";
|
|
6
|
-
import
|
|
6
|
+
import pg from "pg";
|
|
7
7
|
|
|
8
8
|
//#region src/api/database.ts
|
|
9
|
+
const { Client, Pool: Pool$1 } = pg;
|
|
9
10
|
/**
|
|
10
11
|
* The schema used for migrations.
|
|
11
12
|
*/
|
|
@@ -67,7 +68,7 @@ function dbChanges(table) {
|
|
|
67
68
|
*/
|
|
68
69
|
async function defineDatabase(opts) {
|
|
69
70
|
return drizzle({
|
|
70
|
-
client: new Pool({
|
|
71
|
+
client: new Pool$1({
|
|
71
72
|
application_name: "appos",
|
|
72
73
|
max: 16,
|
|
73
74
|
...opts.poolConfig
|
|
@@ -98,7 +99,7 @@ async function defineTestDatabase(opts) {
|
|
|
98
99
|
}
|
|
99
100
|
const testComponents = parsePostgresUrl(opts.connectionString);
|
|
100
101
|
testComponents.database = dbName;
|
|
101
|
-
const testPool = new Pool({ connectionString: buildPostgresUrl(testComponents) });
|
|
102
|
+
const testPool = new Pool$1({ connectionString: buildPostgresUrl(testComponents) });
|
|
102
103
|
const db = drizzle({
|
|
103
104
|
client: testPool,
|
|
104
105
|
logger: opts.logger ? new DatabaseLogger(opts.logger) : void 0,
|
|
@@ -198,7 +199,7 @@ async function ensureTemplateDatabase(connectionString, name, logger) {
|
|
|
198
199
|
await maintenanceClient.query(`CREATE DATABASE ${templateDbName} WITH IS_TEMPLATE = true`);
|
|
199
200
|
const components = parsePostgresUrl(connectionString);
|
|
200
201
|
components.database = templateDbName;
|
|
201
|
-
const templatePool = new Pool({ connectionString: buildPostgresUrl(components) });
|
|
202
|
+
const templatePool = new Pool$1({ connectionString: buildPostgresUrl(components) });
|
|
202
203
|
try {
|
|
203
204
|
await migrate(drizzle({
|
|
204
205
|
client: templatePool,
|
|
@@ -2,10 +2,11 @@ import { Logger } from "./logger.mjs";
|
|
|
2
2
|
import { AnyRelations, EmptyRelations } from "drizzle-orm";
|
|
3
3
|
import "drizzle-orm/pg-core";
|
|
4
4
|
import * as drizzle_orm_node_postgres0 from "drizzle-orm/node-postgres";
|
|
5
|
-
import
|
|
5
|
+
import * as pg0 from "pg";
|
|
6
|
+
import pg from "pg";
|
|
6
7
|
|
|
7
8
|
//#region src/api/database.d.ts
|
|
8
|
-
|
|
9
|
+
type PoolConfig = pg.PoolConfig;
|
|
9
10
|
/**
|
|
10
11
|
* Extract qualified table names from db object.
|
|
11
12
|
*/
|
|
@@ -40,7 +41,7 @@ type Database = Awaited<ReturnType<typeof defineDatabase>>;
|
|
|
40
41
|
* @returns The defined database instance.
|
|
41
42
|
*/
|
|
42
43
|
declare function defineDatabase<TSchema extends Record<string, unknown> = Record<string, never>, TRelations extends AnyRelations = EmptyRelations>(opts: DefineDatabaseOptions<TSchema, TRelations>): Promise<drizzle_orm_node_postgres0.NodePgDatabase<TSchema, TRelations> & {
|
|
43
|
-
$client: Pool;
|
|
44
|
+
$client: pg0.Pool;
|
|
44
45
|
}>;
|
|
45
46
|
//#endregion
|
|
46
47
|
export { Database, QualifiedTableNames };
|
|
@@ -2,10 +2,11 @@ import { Logger } from "./logger.mjs";
|
|
|
2
2
|
import { AnyRelations, EmptyRelations } from "drizzle-orm";
|
|
3
3
|
import "drizzle-orm/pg-core";
|
|
4
4
|
import * as drizzle_orm_node_postgres0 from "drizzle-orm/node-postgres";
|
|
5
|
-
import
|
|
5
|
+
import * as pg0 from "pg";
|
|
6
|
+
import pg from "pg";
|
|
6
7
|
|
|
7
8
|
//#region src/api/database.d.ts
|
|
8
|
-
|
|
9
|
+
type PoolConfig = pg.PoolConfig;
|
|
9
10
|
/**
|
|
10
11
|
* Extract qualified table names from db object.
|
|
11
12
|
*/
|
|
@@ -40,7 +41,7 @@ type Database = Awaited<ReturnType<typeof defineDatabase>>;
|
|
|
40
41
|
* @returns The defined database instance.
|
|
41
42
|
*/
|
|
42
43
|
declare function defineDatabase<TSchema extends Record<string, unknown> = Record<string, never>, TRelations extends AnyRelations = EmptyRelations>(opts: DefineDatabaseOptions<TSchema, TRelations>): Promise<drizzle_orm_node_postgres0.NodePgDatabase<TSchema, TRelations> & {
|
|
43
|
-
$client: Pool;
|
|
44
|
+
$client: pg0.Pool;
|
|
44
45
|
}>;
|
|
45
46
|
//#endregion
|
|
46
47
|
export { Database, QualifiedTableNames };
|
|
@@ -2,11 +2,13 @@ import { Logger } from "./logger.mjs";
|
|
|
2
2
|
import * as drizzle_orm0 from "drizzle-orm";
|
|
3
3
|
import { AnyRelations, EmptyRelations } from "drizzle-orm";
|
|
4
4
|
import * as drizzle_orm_node_postgres0 from "drizzle-orm/node-postgres";
|
|
5
|
-
import
|
|
5
|
+
import * as pg0 from "pg";
|
|
6
|
+
import pg from "pg";
|
|
6
7
|
import { PgTable } from "drizzle-orm/pg-core";
|
|
7
8
|
import { MigrationConfig } from "drizzle-orm/migrator";
|
|
8
9
|
|
|
9
10
|
//#region src/api/database.d.ts
|
|
11
|
+
type PoolConfig = pg.PoolConfig;
|
|
10
12
|
/**
|
|
11
13
|
* Extract qualified table names from db object.
|
|
12
14
|
*/
|
|
@@ -69,7 +71,7 @@ declare function dbChanges<T extends PgTable>(table: T): {
|
|
|
69
71
|
* @returns The defined database instance.
|
|
70
72
|
*/
|
|
71
73
|
declare function defineDatabase<TSchema extends Record<string, unknown> = Record<string, never>, TRelations extends AnyRelations = EmptyRelations>(opts: DefineDatabaseOptions<TSchema, TRelations>): Promise<drizzle_orm_node_postgres0.NodePgDatabase<TSchema, TRelations> & {
|
|
72
|
-
$client: Pool;
|
|
74
|
+
$client: pg0.Pool;
|
|
73
75
|
}>;
|
|
74
76
|
/**
|
|
75
77
|
* Options for defining a test database.
|
|
@@ -91,7 +93,7 @@ interface DefineTestDatabaseOptions<TSchema extends Record<string, unknown> = Re
|
|
|
91
93
|
declare function defineTestDatabase<TSchema extends Record<string, unknown> = Record<string, never>, TRelations extends AnyRelations = EmptyRelations>(opts: DefineTestDatabaseOptions<TSchema, TRelations>): Promise<{
|
|
92
94
|
cleanUp: () => Promise<void>;
|
|
93
95
|
db: drizzle_orm_node_postgres0.NodePgDatabase<TSchema, TRelations> & {
|
|
94
|
-
$client: Pool;
|
|
96
|
+
$client: pg0.Pool;
|
|
95
97
|
};
|
|
96
98
|
dbName: string;
|
|
97
99
|
}>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{APPOS_DIR as e,DATABASES_DIR as t}from"../constants.mjs";import{join as n}from"node:path";import{sql as r}from"drizzle-orm";import{drizzle as i}from"drizzle-orm/node-postgres";import{migrate as a}from"drizzle-orm/node-postgres/migrator";import
|
|
1
|
+
import{APPOS_DIR as e,DATABASES_DIR as t}from"../constants.mjs";import{join as n}from"node:path";import{sql as r}from"drizzle-orm";import{drizzle as i}from"drizzle-orm/node-postgres";import{migrate as a}from"drizzle-orm/node-postgres/migrator";import o from"pg";const{Client:s,Pool:c}=o;function l(r,i=`schema`){let a=i===`schema`?`schema-migrations`:`data-migrations`,o=i===`schema`?`schema-migrations`:`data-migrations`;return{migrationsFolder:`${n(e,t)}/${r}/${a}`,migrationsSchema:`public`,migrationsTable:o}}var u=class{#e;constructor(e){this.#e=e}logQuery(e,t){this.#e.info(t,e)}};async function d(e){let t=`test_w${process.env.VITEST_POOL_ID||`0`}_${Date.now()}_${Math.random().toString(36).substring(2,8)}`;await g(e.connectionString,e.name,e.logger);let n=`${e.name}_test_template`,r=m(e.connectionString),a=new s({connectionString:r});await a.connect();try{await a.query(`CREATE DATABASE ${t} WITH TEMPLATE ${n}`)}finally{await a.end()}let o=f(e.connectionString);o.database=t;let l=new c({connectionString:p(o)});return{cleanUp:async()=>{await l.end();let e=new s({connectionString:r});await e.connect();try{await e.query(`SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname = $1`,[t]),await e.query(`DROP DATABASE IF EXISTS ${t}`)}catch(e){console.error(`Could not drop test database:`,e)}finally{await e.end()}},db:i({client:l,logger:e.logger?new u(e.logger):void 0,relations:e.relations,schema:e.schema}),dbName:t}}function f(e){let t=new URL(e);return{database:t.pathname.slice(1)||`postgres`,host:t.hostname,password:decodeURIComponent(t.password),port:Number.parseInt(t.port||`5432`,10),user:decodeURIComponent(t.username)}}function p(e){let{user:t,password:n,host:r,port:i,database:a}=e;return`postgresql://${encodeURIComponent(t)}:${encodeURIComponent(n)}@${r}:${i}/${a}`}function m(e){let t=f(e);return t.database=`postgres`,p(t)}function h(e){let t=0;for(let n=0;n<e.length;n++){let r=e.charCodeAt(n);t=(t<<5)-t+r,t&=t}return Math.abs(t)}async function g(e,t,n){let r=`${t}_test_template`,o=new s({connectionString:m(e)});await o.connect();let d=h(r);try{if(await o.query(`SELECT pg_advisory_lock($1)`,[d]),(await o.query(`SELECT 1 FROM pg_database WHERE datname = $1`,[r])).rowCount===0){await o.query(`CREATE DATABASE ${r} WITH IS_TEMPLATE = true`);let s=f(e);s.database=r;let d=new c({connectionString:p(s)});try{await a(i({client:d,logger:n?new u(n):void 0}),l(t))}finally{await d.end()}}}finally{await o.query(`SELECT pg_advisory_unlock($1)`,[d]),await o.end()}}export{d as defineTestDatabase};
|