( tables: AnyPgTable[], enums: PgEnum<any>[], schemas: PgSchema[], sequences: PgSequence[], roles: PgRole[], policies: PgPolicy[], views: PgView[], matViews: PgMaterializedView[], casing: CasingType | undefined, schemaFilter?: string[], )
| 99 | } |
| 100 | |
| 101 | export const generatePgSnapshot = ( |
| 102 | tables: AnyPgTable[], |
| 103 | enums: PgEnum<any>[], |
| 104 | schemas: PgSchema[], |
| 105 | sequences: PgSequence[], |
| 106 | roles: PgRole[], |
| 107 | policies: PgPolicy[], |
| 108 | views: PgView[], |
| 109 | matViews: PgMaterializedView[], |
| 110 | casing: CasingType | undefined, |
| 111 | schemaFilter?: string[], |
| 112 | ): PgSchemaInternal => { |
| 113 | const dialect = new PgDialect({ casing }); |
| 114 | const result: Record<string, Table> = {}; |
| 115 | const resultViews: Record<string, View> = {}; |
| 116 | const sequencesToReturn: Record<string, Sequence> = {}; |
| 117 | const rolesToReturn: Record<string, Role> = {}; |
| 118 | // this policies are a separate objects that were linked to a table outside of it |
| 119 | const policiesToReturn: Record<string, Policy> = {}; |
| 120 | |
| 121 | // This object stores unique names for indexes and will be used to detect if you have the same names for indexes |
| 122 | // within the same PostgreSQL schema |
| 123 | |
| 124 | const indexesInSchema: Record<string, string[]> = {}; |
| 125 | |
| 126 | for (const table of tables) { |
| 127 | // This object stores unique names for checks and will be used to detect if you have the same names for checks |
| 128 | // within the same PostgreSQL table |
| 129 | const checksInTable: Record<string, string[]> = {}; |
| 130 | |
| 131 | const { |
| 132 | name: tableName, |
| 133 | columns, |
| 134 | indexes, |
| 135 | foreignKeys, |
| 136 | checks, |
| 137 | schema, |
| 138 | primaryKeys, |
| 139 | uniqueConstraints, |
| 140 | policies, |
| 141 | enableRLS, |
| 142 | } = getTableConfig(table); |
| 143 | |
| 144 | if (schemaFilter && !schemaFilter.includes(schema ?? 'public')) { |
| 145 | continue; |
| 146 | } |
| 147 | |
| 148 | const columnsObject: Record<string, Column> = {}; |
| 149 | const indexesObject: Record<string, Index> = {}; |
| 150 | const checksObject: Record<string, CheckConstraint> = {}; |
| 151 | const foreignKeysObject: Record<string, ForeignKey> = {}; |
| 152 | const primaryKeysObject: Record<string, PrimaryKey> = {}; |
| 153 | const uniqueConstraintObject: Record<string, UniqueConstraint> = {}; |
| 154 | const policiesObject: Record<string, Policy> = {}; |
| 155 | |
| 156 | columns.forEach((column) => { |
| 157 | const name = getColumnCasing(column, casing); |
| 158 | const notNull: boolean = column.notNull; |
no test coverage detected