()
| 173 | } |
| 174 | |
| 175 | func (d *PostgresDatabase) tableNames() ([]string, error) { |
| 176 | // When SkipPartition is true, exclude partitioned parent tables (relkind='p'). |
| 177 | // Otherwise, include both regular tables ('r') and partitioned parent tables ('p'). |
| 178 | relkindCondition := "c.relkind in ('r', 'p')" |
| 179 | if d.config.SkipPartition { |
| 180 | relkindCondition = "c.relkind = 'r'" |
| 181 | } |
| 182 | |
| 183 | query := fmt.Sprintf(` |
| 184 | SELECT n.nspname AS table_schema, relname AS table_name FROM pg_catalog.pg_class c |
| 185 | INNER JOIN pg_catalog.pg_namespace n ON c.relnamespace = n.oid |
| 186 | WHERE n.nspname NOT IN ('information_schema', 'pg_catalog', 'sys') |
| 187 | AND %s |
| 188 | AND c.relpersistence IN ('p', 'u') |
| 189 | AND c.relispartition = false |
| 190 | AND NOT EXISTS (SELECT 1 FROM pg_catalog.pg_depend d WHERE c.oid = d.objid AND d.classid = (SELECT oid FROM pg_catalog.pg_class WHERE relname = 'pg_class') AND d.deptype = 'e') |
| 191 | ORDER BY n.nspname ASC, relname ASC; |
| 192 | `, relkindCondition) |
| 193 | |
| 194 | rows, err := d.db.Query(query) |
| 195 | if err != nil { |
| 196 | return nil, err |
| 197 | } |
| 198 | defer rows.Close() |
| 199 | |
| 200 | tables := []string{} |
| 201 | for rows.Next() { |
| 202 | var schema, name string |
| 203 | if err := rows.Scan(&schema, &name); err != nil { |
| 204 | return nil, err |
| 205 | } |
| 206 | if d.config.TargetSchema != nil && !slices.Contains(d.config.TargetSchema, schema) { |
| 207 | continue |
| 208 | } |
| 209 | tables = append(tables, schema+"."+name) |
| 210 | } |
| 211 | if err := rows.Err(); err != nil { |
| 212 | return nil, err |
| 213 | } |
| 214 | return tables, nil |
| 215 | } |
| 216 | |
| 217 | // partitionChildTables exports CREATE TABLE ... PARTITION OF statements for partition child tables |
| 218 | func (d *PostgresDatabase) partitionChildTables() ([]string, error) { |
no test coverage detected