Skip to content

Commit 0e4e7a5

Browse files
Merge pull request #18 from geoCML/ignore-tables
Optionally ignore tables during write
2 parents 63143ff + 16710e2 commit 0e4e7a5

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,6 @@ Tabor v0.1.2 can be downloaded directly from this repository (under Releases). A
5555

5656
`tabor read --file <path/to/file>` -> Converts a .tabor file into a PostGIS schema query.
5757

58-
`tabor write --file <path/to/file> --db <name_of_psql_db> --username <name of db user> --password <password of db user?> --host <host of psql db?> --port <port of psql db?>` -> Converts a PostGIS database to a .tabor file'
58+
`tabor write --file <path/to/file> --db <name_of_psql_db> --username <name of db user> --password <password of db user?> --host <host of psql db?> --port <port of psql db?> --ignore <tables to ignore?>` -> Converts a PostGIS database to a .tabor file'
5959

6060
`tabor load --file <path/to/file> --db <name_of_psql_db> --username <name of db user> --password <password of db user?> --host <host of psql db?> --port <port of psql db?>` -> Loads a PostGIS database from a .tabor file.'

src/tabor.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
sys.tracebacklimit = -1
1212

1313

14-
def load(file_path: str, db: str, username: str, password: str, host: str, port: str):
14+
def load(file_path: str, db: str, username: str, password: str, host: str, port: str) -> None:
1515
try:
1616
db_connector = DBConnector(db, username, password, host, port)
1717

@@ -40,7 +40,7 @@ def read(file_path: str) -> None:
4040
print(tabor_src.to_psql())
4141

4242

43-
def write(file_path: str, db: str, username: str, password: str, host: str, port: str) -> None:
43+
def write(file_path: str, db: str, username: str, password: str, host: str, port: str, ignore_tables: list) -> None:
4444
try:
4545
data = {}
4646
db_connector = DBConnector(db, username, password, host, port)
@@ -50,6 +50,9 @@ def write(file_path: str, db: str, username: str, password: str, host: str, port
5050
schema = table.split(".")[0]
5151
table_name = table.split(".")[1]
5252

53+
if table_name in ignore_tables:
54+
continue
55+
5356
data[table] = {}
5457
data[table]["fields"] = db_connector.get_fields_for_table(schema, table_name)
5558
data[table]["constraints"] = db_connector.get_triggers_for_table(table_name)
@@ -79,6 +82,8 @@ def write(file_path: str, db: str, username: str, password: str, host: str, port
7982
parser.add_argument('--password', help='The password of a database user.', default=None)
8083
parser.add_argument('--host', help='The hostname of the PostGIS database to connect to.', default="localhost")
8184
parser.add_argument('--port', help='The port of the PostGIS database to connect to.', default=5432)
85+
parser.add_argument('--ignore', nargs="+", help='Any tables to ignore when writing to the .tabor file.', default=[])
86+
8287

8388
args = parser.parse_args()
8489

@@ -96,7 +101,7 @@ def write(file_path: str, db: str, username: str, password: str, host: str, port
96101
if not args.username:
97102
raise Exception("You must provide a PostGIS database user to connect to your database (--username)")
98103

99-
write(args.file, args.db, args.username, args.password, args.host, args.port)
104+
write(args.file, args.db, args.username, args.password, args.host, args.port, args.ignore)
100105
elif args.command == "load":
101106
if not args.file:
102107
raise Exception("You must provide one file to load from (--file)")

0 commit comments

Comments
 (0)