901 Commits

Author SHA1 Message Date
Dimitri Fontaine
bc1167d3e3 Implement support for DB3 MEMO files.
The support code is actually found in cl-db3, the changes that are necessary
for pgloader are only about updating to the new API.

Fixes #926.
2019-04-14 22:22:33 +02:00
Dimitri Fontaine
39fc78e08f Implement user-defined casting rules support for DB3.
The casting support for DB3 was hand-crafted and didn't get upgraded to
using the current CAST grammar and facilities, for no other reasons than
lack of time and interest. It so happens what implementing it now fixes two
bug reports.

Bug #938 is about conversion defaulting to "not null" column, and that's due
to the usage of the internal pgloader catalogs where the target column's
nullable field is NIL by default, which doesn't make much sense. With
support for user-defined casting rules, the default is nullable columns, so
that's kind of a free fix.

Fixes #927.
Fixes #938.
2019-04-14 21:46:04 +02:00
Dimitri Fontaine
efe70ba3c3 Fix MySQL Materialized Views support, recently broken.
When adding support for Mat Views to MS SQL, we added support for the view
names to be fully qualified (with their schema), using a cons to host
the (schema . name) data.

Well, turns out the MySQL side of things didn't get the memo.

Blind attempt at fixing #932, see also #918.
2019-04-14 00:37:40 +02:00
Dimitri Fontaine
c83a0375a0 Fix glitch in Materialized Views support for MSSQL.
Thanks to @sorix6 for a bug report with a fix!

Fixes #928.
2019-04-14 00:23:37 +02:00
Dimitri Fontaine
957caa877e Add a new transform function for byte-vector to hexadecimal string.
In some cases when migrating from MySQL we want to transform data from
binary representation to an hexadecimal number. One such case is going from
MySQL binary(16) to PostgreSQL UUID data type.

Fixes #904.
2019-03-18 14:21:33 +01:00
Dimitri Fontaine
4d005b5c9c Improve Postgres connection string parsing.
Add support for single-quoting database name as in the Postgres
documentation about connection string at:

  https://www.postgresql.org/docs/10/libpq-connect.html#LIBPQ-CONNSTRING

In passing, allow for ipv6 as well as ipv4 host ip addresses.

Fixes #923.
2019-03-17 17:25:41 +01:00
Andreas Hildebrandt
4ec8613884 Correctly parse PostgreSQL version string on Windows.
The regex used in parse-postgresql-version-string failed to handle
"PostgreSQL 10.6, compiled by Visual C++ build 1800, 64-bit"
correctly.
2019-02-25 15:48:40 +01:00
Dimitri Fontaine
0081fb6560 Oops, fix trailing closing parens.
When using interactive recompiling of the code in Emacs/SLIME, extra closing
parens are just ignored in Emacs before sending the current form to the CL
compiler. When compiling from the source files, of course, that doesn't
work.

See #910.
2019-02-19 12:50:56 +01:00
Dimitri Fontaine
fbdc95ede6 Fix parsing of MS GUID with mixed endianness.
It turns out that MS SQL Server is using its own representation for GUID
with a mixed endianness. In this blind patch we attempt to parse the binary
vector in the right way when building our internal representation of an
UUID, before making a string out of it for Postgres, which doesn't use the
same mixed-endianness format.

Fixes #910. Maybe?
2019-02-18 19:37:42 +01:00
Dimitri Fontaine
7c146c46b9 Citus support small bug fixes.
When calling the create_distributed_table() function, the column name is
given as a literal parameter to the function and should be quoted that way,
with single quotes. In particular, if our column-name is already
double-quoted, we need to get rid of those extra quotes.

Also, the source-table-name might be a cons object when qualified, or a
plain string when not schema-qualified. Adjust the citus-find-table code to
take that into account.
2019-02-16 15:48:46 +01:00
Dimitri Fontaine
2e6a941d25 Restore --list-encodings option.
It got broken, somehow. Let's move it further up the chain of command line
option processing.

Fixed #909.
2019-02-15 21:18:38 +01:00
Dimitri Fontaine
69d9b381dc Fix previous patch: also process the bad row.
The bad row needs to go to the reject file, and its condition error message
to the reject log. Ooops, forgot.

See #836.
2019-02-15 00:07:39 +01:00
Dimitri Fontaine
632f7f5b4e Implement COPY error handling for non-parsable error messages.
pgloarder parses the COPY error messages to find out the line number where
we have a problem in the batch, allowing for a quite efficient recovery
mechanism where it's easy enough to just skip the known faulty input.

Now, some error messages do not contain a COPY line number, such as fkey
violation messages:

  Database error 23503: insert or update on table "produtos" violates
  foreign key constraint "produtos_categorias_produtos_fk"

In that case rather than failing the whole batch at once (thanks to the
previous commit, we used to just badly fail before that), we can retry the
batch one row at a time until we find our culprit, and then continue one
input row at a time.

Fixes #836.
2019-02-15 00:05:47 +01:00
Dimitri Fontaine
8eea90bb51 Improve Foreign Key error handling.
We don't know how to parse the PostgreSQL condition sent when there is a
fkey error... and the message would not contain the row number where that
error happened anyway.

At the moment it means that the retry-batch facility errors out for failing
to realize that NIL isn't a number on which we can do arithmetic, which in
itself in a little sad.

In this patch we install a condition handler that knows how to deal with
retry-batch failing, so that pgloader may try and continue rather than
appear locked to the user, when I suspect that the debugger is waiting for
input.

See #836, where that's the first half of the fix. The real fix is to handle
foreign key errors correctly of course.
2019-02-14 23:10:12 +01:00
Dimitri Fontaine
2cbf716112 Ensure column names are double-quoted in the COPY command.
In some cases we have to quote column names and it's not been done yet, for
instance when dealing with PostgreSQL as a source database.

Patch mostly from @m0n5t3r, only cosmetic changes applied. Thanks!

Fixes #905.
2019-02-14 22:16:53 +01:00
Dimitri Fontaine
0caa9c30ce Fix Postgres to Postgres migrations with schema name change.
When migrating from PostgreSQL, pgloader takes the index and foreign key
definitions from the server directly, using pg_get_indexdef() and other
catalog functions. That's very useful in that it embeds all the necessary
quoting of the objects, and schema-qualify them.

Of course we can't use the SQL definition as on the source system when we
target a schema name that is different from the source system, which the
code didn't realize before this patch. Here we simply invalidate the
pre-computed SQL statement and resort to using the classic machinery to
build the statement from pieces again.

Fixes #903.
2019-02-14 18:24:50 +01:00
Dimitri Fontaine
213edbe930 Compare type names case-insensitively in casting rules.
The types TEXT and text are the same, and should match both when used as a
casting rule and when checking a catalog merge.

See #132.
2019-02-05 18:26:40 +03:00
ChristophKaser
36fbadded6 Allow "preserve index names" for MSSQL (#902)
With this change, preserve index names is also supported for MSSQL-connections.
2019-02-05 11:08:23 +03:00
Dimitri Fontaine
eafaf80b3c Back to non-release development.
Master's branch is now preparing for 3.6.2.
2019-01-21 17:51:44 +01:00
Dimitri Fontaine
25c937879a Fix building for 3.6.1.
The pgloader-image feature must be added in the lisp image before
reading/compiling the pgloader sources for it to be useful.
2019-01-21 15:02:39 +01:00
Dimitri Fontaine
dae5dec03c Allow fields/columns projections when parsing header.
When using a CSV header, we might find fields in a different order than the
target table columns, and maybe not all of the fields are going to be read.
Take account of the header we read rather than expecting the header to look
like the target table definition.

Fix #888.
2019-01-15 22:39:08 +01:00
Dimitri Fontaine
1306b4c953 Desultory improvements.
Killing tasks in the error handling must be done carefully, and given this
testing session it seems better to refrain from doing it when erroring out
at COPY init time (missing column is an example of that). The approach
around that is still very much ad-hoc rather than systematic.

In passing improve the `make save` option to producing a binary image: have
the make recipe respect the CL variable. The command line options
differences were already accounted for.
2019-01-09 18:57:33 +01:00
Dimitri Fontaine
2147a1d07b Implement ALTER TABLE ... SET TABLESPACE ... as a pgloader clause.
This allows creating tables in any target tablespace rather than the default
one, and is supported for the various sources having support for the ALTER
TABLE clause already.
2019-01-08 22:50:24 +01:00
Dimitri Fontaine
f28f8e577d Review log-level for stored procedures.
Some MySQL schema level features (on update current_timestamp) are migrated
to stored procedures and triggers. We would log the CREATE PROCEDURE
statements as LOG level entries instead of SQL level entries, most likely a
stray devel/debug choice.
2019-01-08 22:44:07 +01:00
Dimitri Fontaine
a4a52db594 Improve SQLite support for autoincrement and sequences.
It turns out that SQLite only creates an entry in its sqlite_sequence
catalogs when some data make it to a table using a sequence, not at create
table time. It means that pgloader must do some more catalog querying to
figure out if a column is "autoincrement", and apparently the only way to
get to the information is to parse the SQL statement given in the
sqlite_master table.

Fixes #882.
2019-01-07 23:52:29 +01:00
Dimitri Fontaine
204a0119cd Add another debugging guard #+pgloader-image. 2019-01-07 23:51:58 +01:00
Dimitri Fontaine
e4a4edb276 Make interactive debugging easier.
It's fair game to handle errors and issue logs instead when using the
pgloader binary image, as it distracts users a lot. That said, as a
developer the interactive debugger is very useful.

In passing install some experimental thread killing behavior in case of
errors and using on-error-stop setting (default for database migrations).
2019-01-07 20:44:16 +01:00
Dimitri Fontaine
9ce4088b48 Improvements to the make save facility. 2019-01-07 20:44:16 +01:00
Dimitri Fontaine
b8e8cf7d18 Fix bugs in the recent extended support for materialized views.
Materialized views without an explicit schema name are supported, but then
would raise an error when trying to use destructuring-bind on a string
rather than the (cons schema-name table-name). This patch fixes that.
2018-12-28 10:53:01 +01:00
Dimitri Fontaine
65d323e4a3 Refrain from matching typemod expression to NIL typemod.
Fixes #879.
2018-12-23 20:51:36 +01:00
Dimitri Fontaine
c019c16113 Implement MATERIALIZE VIEWS support for MS SQL, and distribute.
The latter is not tested yet, but should have no impact if not used. Given
how rare it is that I get a chance to play around with a MS SQL instance
anyway, it might be better to push blind changes for it when it doesn't
impact existing features…
2018-12-19 01:25:27 +01:00
Dimitri Fontaine
bda06f8ac0 Implement Citus support from a MySQL database. 2018-12-17 16:31:47 +01:00
Dimitri Fontaine
290ad68d61 Implement materialize views in PostgreSQL source support. 2018-12-16 23:17:37 +01:00
Dimitri Fontaine
af2995b918 Apply quoting rules to SQLite index column names.
The previous fix was wrong for missing the point: rather than unquote column
names in the table definition when matching the column names in the index
definition, we should in the first place have quoted the index column names
when needed.

Fixes #872 for real this time.
2018-12-02 00:17:26 +01:00
Dimitri Fontaine
a939d20dff Unquote names when searching for an index column name in its table.
If the source database is using a keyword (such as "order") as a column
name, then pgloader is going to quote this column name in its internal
catalogs. In that case, unquote the column in the pgloader catalogs when
matching it against the unquoted column name we have in the index
definition.

Fixes #872.
2018-12-01 21:27:26 +01:00
Dimitri Fontaine
ab2cadff24 Simplify the regular expresion parsing the PostgreSQL version string.
The debian/Ubuntu packaging would defeat the quite simple regexp parsing
PostgreSQL version string that we have in pgloader. To make it more robust,
make it more open to unforeseen strings.

See #800, see #810.
2018-11-30 15:39:27 +01:00
Dimitri Fontaine
801d8a6e09 Add support for MS SQL time data type.
As for the other datetime types we have to use CONVERT at the SQL level in
order to get a format that PostgreSQL understands. This time the magic
number for it is 114.
2018-11-23 10:43:58 +01:00
Dimitri Fontaine
6e325f67e0 Implement the save.lisp idea for the bundle.
This should make it easier to build pgloader with CCL rather than SBCL, all
from the bundle distribution, and also easier to support windows.

In passing, add a new file in the bundle distribution: version.sexp should
contain a CL string containing the pgloader version string.
2018-11-21 21:44:56 +01:00
Dimitri Fontaine
18bcf10903 Blind fix for a strange use-case.
A user reported a case where pgloader fails to find the table an index has
been created on in pgloader catalogs. That's a weird case. For now, just
issue a warning about the situation and skip the index.
2018-11-21 18:17:34 +01:00
Dimitri Fontaine
4ab26e5387 Handle other conditions in process-catalogs.
It might be that some random condition is signaled during process-catalogs,
causing the errors reported so far and that I can't reproduce. Let's add
some handler-case protection to have more clues about what could be
happening.

See #865, #800, #810, #859, #824.
2018-11-21 17:31:11 +01:00
Dimitri Fontaine
743769d750 Improve handling of errors when fetching the source catalogs.
We might have MS SQL failures at this stage, or even Redshift or other
PostgreSQL variants failing to execute our catalog queries. Handle
conditions by cleanly logging them and returning from copy-database without
doing anything. That's the best we can do here.

Fixes #605, fixes #757.
2018-11-21 10:38:19 +01:00
Dimitri Fontaine
1c18b41cd7 Implement a new way of building pgloader: make save.
This time we directly call into the save-lisp-and-die feature of the
implementation. As pgloader only supports SBCL and CCL at the time being,
doing things without an abstraction layer is easy enough.

This needs more testing and a special version for the bundle case too. One
step at a time, etc.
2018-11-20 22:59:43 +01:00
Dimitri Fontaine
3f2f10eef1 Finish implementation of CAST rules for PostgreSQL source databases.
Add a link to the table from the internal catalogs for columns so that we
can match table-source-name in cast rules when migrating from PostgreSQL.
2018-11-19 19:33:37 +01:00
Dimitri Fontaine
aa8ae159e2 Improve error handling when applying Citus distribution rules.
Make it so that we generate a proper error message to the user when failing
to figure out the PATH to the distribution key, rather than failing with an
internal error about The value NIL is not of type PGLOADER.CATALOG:TABLE.
2018-11-18 18:21:51 +01:00
Dimitri Fontaine
f07ac61269 Fix default/serial handling of pgsql as a source.
In the recent patch that added support for Redshift "identity" columns, we
broke support for PostgreSQL sequences. Unbreak that.
2018-11-18 17:46:41 +01:00
Dimitri Fontaine
1fd0576ace Fix Citus support related debug print instructions. 2018-11-16 00:08:27 +01:00
Dimitri Fontaine
8b1acbae87 Make sure the image knows how to print circular data structures.
Our catalogs representation is designed to be circular, which helps
navigating the graph from anywhere when processing it. This means that we
need to have *print-circle* set to t in the pgloader image, otherwise we
might run into Control stack exhausted when trying to print out debug
information...

Fixes #865, #800, #810, #859, #824.
2018-11-16 00:03:31 +01:00
Dimitri Fontaine
e291c502ba Install a call to cl+ssl:reload at image startup time, again.
Testing shows that it's not just debian which needs it, it's always
necessary. Just re-add our tweak now.

See #866, see #816, see #807, #794.
2018-11-15 23:59:51 +01:00
Dimitri Fontaine
16dda01f37 Deal with SSL verify error the wrong way.
This patch adds an option --no-ssl-cert-verification that allows bypassing
OpenSSL server certificate verification. It's hopefully a temporary measure
that we set up in order to make progress when confronted to:

  SSL verify error: 20 X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY

The real solution is of course to install the SSL certificates at a place
where pgloader will look for them, which defaults to
~/.postgresql/postgresql.crt at the moment. It's not clear what the story is
with the defaults from /etc/ssl, or how to make things happen in a better
way.

See #648, See #679, See #768, See #748, See #775.
2018-11-15 00:13:21 +01:00
Dimitri Fontaine
5ecf04acb9 Implement null if support as a WITH option.
This gives a default "null if" option to all the input columns at once, and
it's still possible to override the default per column.

In passing, fix project-fields declarations that SBCL now complains about
when they're not true, such as declaring a vector when we might have :null
or nil. As a result, remove the (declare (optimize speed)) in the generated
field processing code.
2018-11-13 21:41:27 +01:00