feat: sql-tools overrides (#19796)

This commit is contained in:
Jason Rasmussen 2025-07-08 08:17:40 -04:00 committed by GitHub
parent 1f9813a28e
commit df4a27e8a7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
114 changed files with 775 additions and 289 deletions

View file

@ -1,14 +1,14 @@
import { sql } from 'kysely';
import { DatabaseReader } from 'src/sql-tools/types';
import { Reader } from 'src/sql-tools/types';
export const readFunctions: DatabaseReader = async (schema, db) => {
export const readFunctions: Reader = async (ctx, db) => {
const routines = await db
.selectFrom('pg_proc as p')
.innerJoin('pg_namespace', 'pg_namespace.oid', 'p.pronamespace')
.leftJoin('pg_depend as d', (join) => join.onRef('d.objid', '=', 'p.oid').on('d.deptype', '=', sql.lit('e')))
.where('d.objid', 'is', sql.lit(null))
.where('p.prokind', '=', sql.lit('f'))
.where('pg_namespace.nspname', '=', schema.schemaName)
.where('pg_namespace.nspname', '=', ctx.schemaName)
.select((eb) => [
'p.proname as name',
eb.fn<string>('pg_get_function_identity_arguments', ['p.oid']).as('arguments'),
@ -17,7 +17,7 @@ export const readFunctions: DatabaseReader = async (schema, db) => {
.execute();
for (const { name, expression } of routines) {
schema.functions.push({
ctx.functions.push({
name,
// TODO read expression from the overrides table
expression,