Skip to content

Commit

Permalink
Fix issue #998 - match on table OID
Browse files Browse the repository at this point in the history
  • Loading branch information
sualeh committed Jan 20, 2023
1 parent 1146b13 commit dd7eca0
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ SELECT
FROM
PG_CATALOG.PG_CLASS C
INNER JOIN PG_CATALOG.PG_NAMESPACE NC
ON C.RELOWNER = NC.NSPOWNER
ON C.RELNAMESPACE = NC.OID
WHERE
C.RELKIND IN ('r', 'v')
AND NC.NSPNAME NOT IN ('pg_catalog', 'information_schema')
AND NC.NSPNAME !~ '^pg_toast'
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,13 @@
import static schemacrawler.test.utility.FileHasContent.hasSameContentAs;
import static schemacrawler.test.utility.FileHasContent.outputOf;
import static schemacrawler.test.utility.TestUtility.javaVersion;
import static schemacrawler.test.utility.TestUtility.writeStringToTempFile;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import org.junit.jupiter.api.BeforeEach;
Expand All @@ -70,6 +73,7 @@
import schemacrawler.tools.command.text.schema.options.SchemaTextOptions;
import schemacrawler.tools.command.text.schema.options.SchemaTextOptionsBuilder;
import schemacrawler.tools.executable.SchemaCrawlerExecutable;
import us.fatehi.utility.ObjectToString;

@HeavyDatabaseTest
@Testcontainers
Expand Down Expand Up @@ -125,6 +129,13 @@ public void testPostgreSQLWithConnection() throws Exception {
final Catalog catalog = executable.getCatalog();

final Table table = catalog.lookupTable(new SchemaReference(null, "books"), "authors").get();

final Map<String, Map<?, ?>> tableMap = new HashMap<>();
tableMap.put(table.getFullName(), table.getAttributes());
assertThat(
outputOf(writeStringToTempFile(ObjectToString.toString(tableMap))),
hasSameContentAs(classpathResource("tableAttributes.json")));

final Column column = table.lookupColumn("firstname").get();
assertThat(column.getPrivileges(), is(not(empty())));

Expand Down
40 changes: 40 additions & 0 deletions schemacrawler-postgresql/src/test/resources/tableAttributes.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"books.authors": {
"REF_GENERATION": "",
"RELACL": "{test=arwdDxt/test,otheruser=r/test}",
"RELALLVISIBLE": 0,
"RELAM": 0,
"RELCHECKS": 1,
"RELFILENODE": 16440,
"RELFORCEROWSECURITY": false,
"RELFROZENXID": "564",
"RELHASINDEX": true,
"RELHASOIDS": false,
"RELHASPKEY": true,
"RELHASRULES": false,
"RELHASSUBCLASS": false,
"RELHASTRIGGERS": true,
"RELISPOPULATED": true,
"RELISSHARED": false,
"RELKIND": "r",
"RELMINMXID": "1",
"RELNAME": "authors",
"RELNAMESPACE": 16385,
"RELNATTS": 9,
"RELOFTYPE": 0,
"RELOWNER": 10,
"RELPAGES": 0,
"RELPERSISTENCE": "p",
"RELREPLIDENT": "d",
"RELROWSECURITY": false,
"RELTABLESPACE": 0,
"RELTOASTRELID": 16445,
"RELTUPLES": 0.0,
"RELTYPE": 16442,
"REMARKS": "Contact details for book authors",
"SELF_REFERENCING_COL_NAME": "",
"TYPE_CAT": "",
"TYPE_NAME": "",
"TYPE_SCHEM": ""
}
}

0 comments on commit dd7eca0

Please sign in to comment.