diff --git a/README.md b/README.md index d1f61c6c..17c8096b 100644 --- a/README.md +++ b/README.md @@ -104,8 +104,14 @@ Pongo uses the following table structure for storing collections: ```sql CREATE TABLE IF NOT EXISTS "YourCollectionName" ( - _id UUID PRIMARY KEY, - data JSONB + _id TEXT PRIMARY KEY, + data JSONB NOT NULL, + metadata JSONB NOT NULL DEFAULT '{}', + _version BIGINT NOT NULL DEFAULT 1, + _partition TEXT NOT NULL DEFAULT 'png_global', + _archived BOOLEAN NOT NULL DEFAULT FALSE, + _created TIMESTAMPTZ NOT NULL DEFAULT now(), + _updated TIMESTAMPTZ NOT NULL DEFAULT now() ) ``` diff --git a/src/docs/getting-started.md b/src/docs/getting-started.md index 24eb8a10..a728f08a 100644 --- a/src/docs/getting-started.md +++ b/src/docs/getting-started.md @@ -102,8 +102,14 @@ Pongo uses the following table structure for storing collections: ```sql CREATE TABLE IF NOT EXISTS "YourCollectionName" ( - _id UUID PRIMARY KEY, - data JSONB + _id TEXT PRIMARY KEY, + data JSONB NOT NULL, + metadata JSONB NOT NULL DEFAULT '{}', + _version BIGINT NOT NULL DEFAULT 1, + _partition TEXT NOT NULL DEFAULT 'png_global', + _archived BOOLEAN NOT NULL DEFAULT FALSE, + _created TIMESTAMPTZ NOT NULL DEFAULT now(), + _updated TIMESTAMPTZ NOT NULL DEFAULT now() ) ``` diff --git a/src/packages/pongo/src/postgres/postgresCollection.ts b/src/packages/pongo/src/postgres/postgresCollection.ts index 86878b14..1e60d40e 100644 --- a/src/packages/pongo/src/postgres/postgresCollection.ts +++ b/src/packages/pongo/src/postgres/postgresCollection.ts @@ -179,7 +179,16 @@ export const postgresCollection = ( export const collectionSQLBuilder = (collectionName: string) => ({ createCollection: (): SQL => sql( - 'CREATE TABLE IF NOT EXISTS %I (_id UUID PRIMARY KEY, data JSONB)', + `CREATE TABLE IF NOT EXISTS %I ( + _id TEXT PRIMARY KEY, + data JSONB NOT NULL, + metadata JSONB NOT NULL DEFAULT '{}', + _version BIGINT NOT NULL DEFAULT 1, + _partition TEXT NOT NULL DEFAULT 'png_global', + _archived BOOLEAN NOT NULL DEFAULT FALSE, + _created TIMESTAMPTZ NOT NULL DEFAULT now(), + _updated TIMESTAMPTZ NOT NULL DEFAULT now() + )`, collectionName, ), insertOne: (document: WithId): SQL =>