Fix DROP TABLE statements on tables with foreign keys

This commit is contained in:
Alex Baretta 2015-05-26 17:32:58 -07:00
parent 817fc9a258
commit 49dcae8068
2 changed files with 23 additions and 7 deletions

View File

@ -1433,11 +1433,19 @@ The `database` command accepts the following clauses and options:
- *include drop* - *include drop*
When this option is listed, pgloader drop in the PostgreSQL When this option is listed, pgloader drops all the tables in the
connection all the table whose names have been found in the MySQL target PostgreSQL database whose names appear in the SQLite
database. This option allows for using the same command several database. This option allows for using the same command several
times in a row until you figure out all the options, starting times in a row until you figure out all the options, starting
automatically from a clean environment. automatically from a clean environment. Please note that `CASCADE`
is used to ensure that tables are dropped even if there are foreign
keys pointing to them. This is precisely what `include drop` is
intended to do: drop all target tables and recreate them.
Great care needs to be taken when using `include drop`, as
it will cascade to *all* objects referencing the target tables,
possibly including other tables that are not being loaded from
the source DB.
- *include no drop* - *include no drop*
@ -1857,11 +1865,19 @@ The `sqlite` command accepts the following clauses and options:
- *include drop* - *include drop*
When this option is listed, pgloader drop in the PostgreSQL When this option is listed, pgloader drops all the tables in the
connection all the table whose names have been found in the SQLite target PostgreSQL database whose names appear in the SQLite
database. This option allows for using the same command several database. This option allows for using the same command several
times in a row until you figure out all the options, starting times in a row until you figure out all the options, starting
automatically from a clean environment. automatically from a clean environment. Please note that `CASCADE`
is used to ensure that tables are dropped even if there are foreign
keys pointing to them. This is precisely what `include drop` is
intended to do: drop all target tables and recreate them.
Great care needs to be taken when using `include drop`, as
it will cascade to *all* objects referencing the target tables,
possibly including other tables that are not being loaded from
the source DB.
- *include no drop* - *include no drop*

View File

@ -180,7 +180,7 @@
(defun drop-table-if-exists-sql (table-name) (defun drop-table-if-exists-sql (table-name)
"Return the PostgreSQL DROP TABLE IF EXISTS statement for TABLE-NAME." "Return the PostgreSQL DROP TABLE IF EXISTS statement for TABLE-NAME."
(let ((table-name (apply-identifier-case table-name))) (let ((table-name (apply-identifier-case table-name)))
(format nil "DROP TABLE IF EXISTS ~a;~%" table-name))) (format nil "DROP TABLE IF EXISTS ~a~% CASCADE;" table-name)))
(defun create-table-sql-list (all-columns (defun create-table-sql-list (all-columns
&key &key