10000 feat: add foreign key param on column creation · supabase/postgres-meta@acec2f2 · GitHub
[go: up one dir, main page]

Skip to content

Commit acec2f2

Browse files
committed
feat: add foreign key param on column creation
1 parent da72623 commit acec2f2

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,17 @@
22

33
A RESTful API for managing your Postgres. Fetch tables, add roles, and run queries (and more).
44

5+
### Environment variables
6+
```shell
7+
PG_META_DB_HOST = ${PG_META_DB_HOST}
8+
PG_META_DB_NAME = ${PG_META_DB_NAME}
9+
PG_META_DB_USER = ${PG_META_DB_USER}
10+
PG_META_DB_PASSWORD = ${PG_META_DB_PASSWORD}
11+
PG_META_DB_PORT = ${PG_META_DB_PORT}
12+
PG_META_PORT = ${PG_META_PORT}
13+
```
14+
15+
516
## Documentation
617

718
https://supabase.github.io/postgres-meta/

src/lib/PostgresMetaColumns.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ export default class PostgresMetaColumns {
9191
is_unique = false,
9292
comment,
9393
check,
94-
}: {
94+
foreign_table,
95+
}: {
9596
table_id: number
9697
name: string
9798
type: string
@@ -103,6 +104,7 @@ export default class PostgresMetaColumns {
103104
is_primary_key?: boolean
104105
is_unique?: boolean
105106
comment?: string
107+
foreign_table?: string
106108
check?: string
107109
}): Promise<PostgresMetaResult<PostgresColumn>> {
108110
const { data, error } = await this.metaTables.retrieve({ id: table_id })
@@ -126,6 +128,7 @@ export default class PostgresMetaColumns {
126128
}
127129
const isPrimaryKeyClause = is_primary_key ? 'PRIMARY KEY' : ''
128130
const isUniqueClause = is_unique ? 'UNIQUE' : ''
131+
const foreignClause = foreign_table ? `references ${ident(foreign_table)}` : '';
129132
const checkSql = check === undefined ? '' : `CHECK (${check})`
130133
const commentSql =
131134
comment === undefined
@@ -140,7 +143,8 @@ BEGIN;
140143
${isNullableClause}
141144
${isPrimaryKeyClause}
142145
${isUniqueClause}
143-
${checkSql};
146+
${checkSql}
147+
${foreignClause};
144148
${commentSql};
145149
COMMIT;`
146150
{

0 commit comments

Comments
 (0)
0