From 5de0563641bfabb2a63df084c4d5bdeb57ea0c3b Mon Sep 17 00:00:00 2001 From: Gao Sun Date: Wed, 23 Jun 2021 22:57:18 +0800 Subject: [PATCH] Generate table metadata --- .../schemas/src/db-entries/oidc-model-instance.ts | 15 +++++++++++++++ packages/schemas/src/gen/index.ts | 7 +++++++ packages/schemas/tables/oidc_model_instances.sql | 1 + 3 files changed, 23 insertions(+) diff --git a/packages/schemas/src/db-entries/oidc-model-instance.ts b/packages/schemas/src/db-entries/oidc-model-instance.ts index 646b71836..c3eb09e25 100644 --- a/packages/schemas/src/db-entries/oidc-model-instance.ts +++ b/packages/schemas/src/db-entries/oidc-model-instance.ts @@ -5,7 +5,22 @@ export type OidcModelInstanceDBEntry = { id: string; payload: Record; expiresAt: number; + consumedAt?: number; userCode?: string; uid?: string; grantId?: string; }; + +export const OidcModelInstances = { + table: 'oidc_model_instances', + fields: { + modelName: 'model_name', + id: 'id', + payload: 'payload', + expiresAt: 'expires_at', + consumedAt: 'consumed_at', + userCode: 'user_code', + uid: 'uid', + grantId: 'grant_id', + }, +}; diff --git a/packages/schemas/src/gen/index.ts b/packages/schemas/src/gen/index.ts index 8547d5484..d4018012a 100644 --- a/packages/schemas/src/gen/index.ts +++ b/packages/schemas/src/gen/index.ts @@ -95,6 +95,13 @@ const generate = async () => { )}: ${type}${conditionalString(isArray && '[]')};` ), '};', + '', + `export const ${camelcase(name, { pascalCase: true })} = {`, + ` table: '${name}',`, + ` fields: {`, + ...fields.map(({ name }) => ` ${camelcase(name)}: '${name}',`), + ` },`, + `};`, ].join('\n') ) .join('\n') + diff --git a/packages/schemas/tables/oidc_model_instances.sql b/packages/schemas/tables/oidc_model_instances.sql index 7df2f14f8..30335cd5d 100644 --- a/packages/schemas/tables/oidc_model_instances.sql +++ b/packages/schemas/tables/oidc_model_instances.sql @@ -3,6 +3,7 @@ create table oidc_model_instances ( id varchar(128) not null, payload jsonb not null, expires_at bigint not null, + consumed_at bigint, user_code varchar(128), uid varchar(128), grant_id varchar(128),