Commit Graph

1288 Commits

Author SHA1 Message Date
Gert Van Gool
3109ba14dc Update bootstrap CentOS scripts (#424)
* Corrects CentOS7 instruction (incorrect group name)

* Update CentOS 6 bootstrap info

- More recent SBCL (1.1 -> 1.3)
- Missing freetds dependency
2016-06-17 23:15:29 +02:00
Krzysztof Jurewicz
fa9f437095 Override encoding in every testing connection (#410)
Also: reuse connection in process-regression-test.

Fix #408.
2016-05-31 23:12:41 +02:00
Krzysztof Jurewicz
1378949eee Fix docs about char and varchar casting in MySQL (#409) 2016-05-18 21:55:36 +02:00
Krzysztof Jurewicz
13f5821547 Add the “set not null” cast option for MySQL (#407)
Use case: Django dissuades setting NULL “on string-based fields […]
because empty string values will always be stored as empty strings, not
as NULL. If a string-based field has null=True, that means it has two
possible values for »no data«: NULL, and the empty string. In most
cases, it’s redundant to have two possible values for »no data«; the
Django convention is to use the empty string, not NULL.”.

pgloader already supports custom transformations which can be used to
replace NULL values in string-based columns with empty strings. Setting
NOT NULL constraint on those columns could possibly be achieved by
running a database query to extract their names and then generating
relevant ALTER TABLE statements, but a cast option in pgloader is a more
convenient way.
2016-05-18 21:50:09 +02:00
Dimitri Fontaine
7344e1d81e Improve docs for FILENAMES MATCHING support.
This format of source file specifications is available for CSV, COPY and
FIXED formats but was only documented for the CSV one. The paragraph is
copy/pasted around in the hope to produce per-format man pages and web
documentation in a fully automated way sometime.

Fix #397.
2016-05-18 11:07:28 +02:00
alex
49c9a2f016 add the postgres debian ppa key in the correct way (#406)
* add the postgres debian ppa key in the correct way

* experimental: remove dist-upgrade

* experimental: install asdf/sbcl via apt
2016-05-16 20:19:55 +02:00
alex
09c178c33b makefile: perform shallow clones when cloning deps (#405) 2016-05-16 20:17:47 +02:00
leonardsson
826d975985 Fix bug in max-parallel-create-index (#398)
Fixes #395
2016-05-05 22:00:38 +02:00
porshkevich
65e08fe187 fix type drop to cascade (#393)
if you have function or operator with  type which is removed, you will have error

error: cannot drop type because other objects depend on it
2016-04-27 21:43:02 +02:00
Dimitri Fontaine
44b9ec81c9 Fix non-deterministic projection in MySQL query.
In MySQL the information_schema.statistics table lists all indexes and
has a row per index column, which means that the index level properties
are duplicated on every row of the view.

Our query against that catalog was lazily assuming the classic and
faulty MySQL behavior where GROUP BY would allow non aggregated columns
to be reported even when the result isn't deterministic, this patch
fixes that by using a trick: the NON_UNIQUE column is 0 for a unique
index and 1 otherwise, so we sum the numbers and process 0 equality.

Fix #345 again.
2016-04-27 21:14:59 +02:00
Dimitri Fontaine
7af6c7ac41 Filter out incomplete foreign key definitions.
It's possible that in MySQL a foreign key constraint definition is
pointing to a non-existing table. In such a case, issue an error message
and refrain from trying to then reinstall the faulty foreign key
definition.

The lack of error handling at this point led to a frozen instance of
pgloader apparently, I think because it could not display the
interactive debugger at the point where the error occurs.

See #328, also #337 that might be fixed here.
2016-04-19 17:23:05 -04:00
Dimitri Fontaine
42e9e521e0 Add option "max parallel create index".
By default, pgloader will start as many parallel CREATE INDEX commands
as the maximum number of indexes you have on any single table that takes
part in the load.

As this number might be so great as to exhaust the target PostgreSQL
server (e.g. maintenance_work_mem), we add an option to limit that to
something reasonnable when the source schema isn't.

Fix #386 in which 150 indexes are found on a single source table.
2016-04-11 17:40:52 +02:00
Dimitri Fontaine
31f8b5c5f0 Set application_name to 'pgloader' by default.
It's always been possible to set application_name to anything really,
making it easier to follow the PostgreSQL queries made by pgloader.
Force that setting to 'pgloader' by default.

Fix #387.
2016-04-11 17:14:38 +02:00
Dimitri Fontaine
0805ee32b8 Add a CCL dockerfile.
For some reasons, with the default DYNSIZE and even when using the 64
bits Clozure-CL variant, I get a series of error messages like the one
below, so that I had to restrain to using 256 MB only:

  Fatal error in "buildapp" : Fault during read of memory address #x7F8C37522668
  Fatal error in "buildapp" : Fault during
  Fatal error in "buildapp" : Stack overflow on temp stack.
  Fatal error in "buildapp" : Fault during read of memory address #x7F8C37522668

It's worth trying something else as the limitation might be tied to my
local virtual build environment.

See #327 where the SBCL Garbage Collector is introducing problems which
might not appear at all when compiling with Clozure-CL instead.
2016-04-08 10:44:04 +02:00
Dimitri Fontaine
6d09de995b Add FusionBox to the sponsor page.
FusionBox bought a Moral License and helped test case pgloader against a
test instance of SQL Server with which it was easy to reproduce bugs.
Those got fixed thanks to their support!
2016-04-02 20:46:16 +02:00
Dimitri Fontaine
c439ea4b9c Explicitely allow for Return as whitespace.
Windows default end of line is #\Return then #\Newline and the parser
gets to see both of them, so it needs to be prepared. See #159 which is
all about windows support.
2016-03-30 10:41:50 +02:00
Dimitri Fontaine
7fc0812f79 Can't reduce an empty list with the max function.
The max function requires at least 1 argument to be given, and in the
case where we have no table to load it then fails badly, as show here:

  CL-USER> (handler-case
               (reduce #'max nil)
             (condition (c)
               (format nil "~a" c)))
  "invalid number of arguments: 0"

Of course Common Lisp comes with a very easy way around that problem:

  CL-USER> (reduce #'max nil :initial-value 0)
  0

Fix #381.
2016-03-29 21:02:31 +02:00
deepy
dcc926e90c Adds cast for image -> bytea 2016-03-29 20:54:27 +02:00
Dimitri Fontaine
177f48863b Fix regression testing.
It's been broken by a recent commit where we did force the internal
table representation to always be an instance of the table structure,
which wasn't yet true for regression testing.

In passing, re-indent a large portion of the function, which accounts
for most of the diff.
2016-03-27 21:28:51 +02:00
Dimitri Fontaine
b1d4e94f2a Fix integer parsing support for SQLite.
The function needs to return a string to be added to the COPY stream, we
still need to make sure whatever given here looks like an integer. Given
the very dynamic nature of data types in SQLite, the integer-to-string
function was already a default now, but failed to be published before in
its fixed version, somehow.
2016-03-27 20:42:40 +02:00
Dimitri Fontaine
fe3601b04c Fix SQLite index support, add foreign keys support.
It turns out recent changes broke tne SQLite index support (from adding
support for MS SQL partial/filtered indexes), so fix it by using the
pgsql-index structure rather than the specific sqlite-idx one.

In passing, improve detection of PRIMARY KEY indexes, which was still
lacking. This work showed that the introspection done by pgloader was
wrong, it's way more crazy that we though, so adjust the code to loop
over PRAGMA calls for each object we inspect.

While adding PRAGMA calls, add support for foreign keys too, we have the
code infrastructure that makes it easy now.
2016-03-27 20:39:13 +02:00
Dimitri Fontaine
cdc5d2f06b Review on update CURRENT_TIMESTAMP support.
Make it work on the second run, when the triggers and functions have
already been deplyed, by doing the DROP function and trigger before we
CREATE the table, then CREATE them again: we need to split the list
again.
2016-03-27 19:13:33 +02:00
Dimitri Fontaine
45924be87d Add support for MS SQL newid() function.
The newid() function seems to be equivalent to the newsequentialid() one
if I'm to believe issue #204, so let's just add that assumption in the
code.

Fix #204.
2016-03-27 01:09:22 +01:00
Dimitri Fontaine
d72c711b45 Implement support for on update CURRENT_TIMESTAMP.
That's the MySQL slang for a simple ON UPDATE trigger, and that's what
pgloader nows translate the expression to. Fix #195.
2016-03-27 01:01:40 +01:00
Dimitri Fontaine
156f5a4418 Merge pull request #378 from pylaligand/esrap
Removed reference to defunct build target.
2016-03-26 20:51:10 +01:00
Dimitri Fontaine
35155654df Allow to ALTER TABLE ... IN SCHEMA.
That brings the ALTER TABLE feature to MS SQL source.
2016-03-26 20:50:05 +01:00
Dimitri Fontaine
fcc6e8f813 Implement ALTER SCHEMA ... RENAME TO...
That's only available for MS SQL as of now, as it's the only source
database we have where the notion of a schema makes sense. Fix #224.
2016-03-26 20:25:03 +01:00
Dimitri Fontaine
3d061a5f88 Improve regression tests to detect more errors.
By changing the order of the relations in the EXCEPT query, we can now
detect when the target table is loaded empty.
2016-03-26 20:23:12 +01:00
P.Y. Laligand
8523410555 Removed reference to defunct build target. 2016-03-26 12:19:54 -07:00
Dimitri Fontaine
7b33b9c853 Switch back again to the main esrap code.
The WIP branch about better error messages made its way through the main
code, so switch back to the mainline as available directly in Quicklisp.

See https://github.com/nikodemus/esrap/issues/26.
2016-03-26 18:36:04 +01:00
Dimitri Fontaine
787be7f188 Review fixed source import.
The clone method was missing specific slots of fixed-copy class.
2016-03-26 18:33:04 +01:00
Dimitri Fontaine
6f078daeb9 Ensure logging of errors.
The first error of a batch was lost somewhere in the recent changes. My
current best guess is that the rewrite of the copy-batch function made
the handler-bind form setup by the handling-pgsql-notices macro
ineffective, but I can't see why that is.

See #85.
2016-03-26 17:51:38 +01:00
Dimitri Fontaine
d1cfe90f5d Another MS SQL index filter fix.
The common lisp default printer is nice enough to know how to print
symbols as strings, but that won't cut it when the symbol :is-not-null
needs to be printed out "is not null", without the dashes.

See #365.
2016-03-22 00:37:07 +01:00
Dimitri Fontaine
e2fcd86868 Handle failure to convert index filters gracefully.
We should not block any processing just because we can't parse an index.
The best we can do just tonight is to try creating the index without the
filter, ideally we would have to skip building the index entirely.
That's for a later effort though, it's running late here.

See #365.
2016-03-22 00:29:25 +01:00
Dimitri Fontaine
ac7f326447 Fix support for <> in MS SQL filter parsing.
Beware of the order of the parser attempts...

See #365.
2016-03-22 00:26:43 +01:00
Dimitri Fontaine
44660326d7 Review previous patch.
The only case with a test is the "([deleted]=(0))" case, which showed a
tad too much in the current implementation of the MS SQL index filters
parsing. Try to prepare better for next filters.

Next step: adding some test cases.

See #365.
2016-03-22 00:17:13 +01:00
Dimitri Fontaine
5e18cfd7d4 Implement support for partial indexes.
MS SQL has a notion of a "filtered index" that matches the notion of a
PostgreSQL partial index: the index only applies to the rows matching
the index WHERE clause, or filter.

The WHERE clause in both case are limited to simple expressions over a
base table's row at a time, so we implement a limited WHERE clause
parser for MS SQL filters and a transformation routine to rewrite the
clause in PostgreSQL slang.

In passing, we transform the filter constants using the same
transformation functions as in the CAST rules, so that e.g. a MS SQL
bit(1) value that got transformed into a PostgreSQL boolean is properly
translated, as in the following example:

  MS SQL:     "([deleted]=(0))"  (that's from the catalogs)
  PostgreSQL: deleted = 'f'

Of course the parser is still very badly tested, let's see what happens
in the wild now.

(Should) Fix #365.
2016-03-21 23:39:45 +01:00
Dimitri Fontaine
8fc9a474d9 Document --dry-run and --on-error-stop options. 2016-03-21 21:24:39 +01:00
Dimitri Fontaine
1ed07057fd Implement --on-error-stop command line option.
The implementation uses the dynamic binding *on-error-stop* so it's also
available when pgloader is used as Common Lisp librairy.
The (not-all-that-) recent changes made to the error handling make that
implementation straightforward enough, so let's finally do it!

Fix #85.
2016-03-21 20:52:50 +01:00
Dimitri Fontaine
8476c1a359 Allow setting search_path with multiple schemas.
The PostgreSQL search_path allows multiple schemas and might even need
it to be able to reference types and other tables. Allow setting more
than one schema by using the fact that PostgreSQL schema names don't
need to be individually quoted, and passing down the exact content of
the SET search_path value down to PostgreSQL.

Fix #359.
2016-03-20 20:54:08 +01:00
Dimitri Fontaine
63c3b3b1c7 Fix MS SQL text values processing.
The previous code required non-zero data length for all MS SQL returned
values, where it makes no sense for text like values (an empty string is
ok). Also, the code was trimming spaces from both ends on syb-char data,
and in testing that return type is used for varchar too.

Fix #366. Fix #368.
2016-03-20 20:15:02 +01:00
Dimitri Fontaine
4155d06ae5 Improve support for MS SQL multicolumn indexes.
Once more we can't use an aggregate over a text column in MS SQL to
build the index definition from its catalog structure, so we have to do
that in the lisp part of the code.

Multi-column indexes are now supported, but filtered indexes still are a
problem: the WHERE clause in MS SQL is not compatible with the
PostgreSQL syntax (because of [names] and type casting.

For example we cast MS SQL bit to PostgreSQL boolean, so

  WHERE ([deleted]=(0))

should be translated to

  WHERE not deleted

And the code to do that is not included yet.

The following documentation page offers more examples of WHERE
expression we might want to support:

  https://technet.microsoft.com/en-us/library/cc280372.aspx

  WHERE EndDate IS NOT NULL
    AND ComponentID = 5
    AND StartDate > '01/01/2008'

  EndDate IN ('20000825', '20000908', '20000918')

It might be worth automating the translation to PostgreSQL syntax and
operators, but it's not done in this patch.

See #365, where the created index will now be as follows, which is a
problem because of being UNIQUE: some existing data won't reload fine.

  CREATE UNIQUE INDEX idx_<oid>_foo_name_unique ON dbo.foo (name, type, deleted);
2016-03-18 11:01:06 +01:00
Dimitri Fontaine
d2a1ac639f Fix MS SQL foreign key support.
Avoid registering the first column name twice in the foreign key
definition.
2016-03-16 22:01:01 +01:00
Dimitri Fontaine
4cb83ec6a5 DEBUG mode should list all SQL queries sent.
Even for MS SQL source.
2016-03-16 21:55:40 +01:00
Dimitri Fontaine
3e8b7df0d3 Improve column formatting.
Have a pretty-print option where we try to be nice for the reader, and
don't use it in the CAST debug messages. Also allow working with the
real maximum length of column names rather than hardcoding 22 cols...
2016-03-16 21:46:41 +01:00
Dimitri Fontaine
f1fe9ab702 Assorted fixes to MS SQL support.
Having been given a test instance of a MS SQL database allows to quickly
fix a series of assorted bugs related to schema handling of MS SQL
databases. As it's the only source with a proper notion of schema that
pgloader supports currently, it's not a surprise we had them.

Fix #343. Fix #349. Fix #354.
2016-03-16 21:43:04 +01:00
Dimitri Fontaine
c1fc4f0879 Review MySQL foreign key introspection SQL query.
It turns out sloppy SQL code made its way to pgloader wherein the GROUP
BY clause of the foreign key listing wasn't reference the whole set of
non aggregated output columns.

Thanks to thiagokronig for the new query, which fixes #345.
2016-03-09 18:36:44 +01:00
Dimitri Fontaine
b7a873c03f Drop default value on bigserial CAST in MS SQL.
This is a blind attempt to fix #354.
2016-03-09 18:30:18 +01:00
Dimitri Fontaine
57f7fd1d4e Find foreign keys with #'string= by default.
Blind attempt at fixing #343 and #330, which now is on at the same
level.
2016-03-09 16:33:44 +01:00
Dimitri Fontaine
c724018840 Implement ALTER TABLE clause for MySQL migrations.
The new ALTER TABLE facility allows to act on tables found in the MySQL
database before the migration happens. In this patch the only provided
actions are RENAME TO and SET SCHEMA, which fixes #224.

In order to be able to provide the same option for MS SQL users, we will
have to make it work at the SCHEMA level (ALTER SCHEMA ... RENAME TO
...) and modify the internal schema-struct so that the schema slot of
our table instances are a schema instance rather than its name.

Lacking MS SQL test database and instance, the facility is not yet
provided for that source type.
2016-03-06 21:51:33 +01:00