NAME
DBIO::DuckDB::Diff::Rebuild - Rebuild a DuckDB table for what ALTER TABLE cannot do
VERSION
version 0.900007
DESCRIPTION
DuckDB cannot drop a column while an index or a UNIQUE constraint stands on it or on a later column, cannot drop a UNIQUE constraint, and has no ALTER TABLE for a foreign key. The diff then replaces the table's column and index operations by one of these, after the pattern of dbio-sqlite (its ADR 0003): a new table with the target's definition under a temporary name (NAME__dbio_rebuild, in the schema of the table), the rows of the columns both tables have copied, the old table dropped, the new one renamed, and the table's indexes of the target created again behind it (ordinary DBIO::DuckDB::Diff::Index operations).
The statements carry no transaction of their own. "_execute_diff" in DBIO::DuckDB::Deploy runs the whole diff in one, so a copy that fails -- a row the new key or NOT NULL refuses -- takes the rebuild and everything before it back.
What the rebuild cannot do is refused by DBIO::DuckDB::Deploy before the first statement (see "_check_before_apply" in DBIO::DuckDB::Deploy): DuckDB does not drop a table another one has a foreign key to, and a table that points to itself keeps the temporary name in its key after the rename.
column_ops holds the DBIO::DuckDB::Diff::Column operations the rebuild replaces; they render nothing, but the deploy still looks at their rows (a new NOT NULL column without a default).
A rebuild that drops a column, or changes one so that values can be lost ("lossy"), runs only with allow_destructive (ADR 0011).
METHODS
tmp_name
The name the new table has until the rename.
as_sql
lossy_columns
The names of the columns whose values the rebuild can lose or alter: the ones its column_ops drop and the ones they change with "lossy" in DBIO::DuckDB::Diff::Column (the same pair list, ADR 0011). A rebuild copies every column the new table shares with the old one unchanged, so the other columns keep their values.
lossy
True when "lossy_columns" names a column, so that "apply" in DBIO::Deploy::Base runs the rebuild only with allow_destructive. A rebuild that carries every column over unchanged (a UNIQUE dropped, a foreign key added) is not lossy.
summary
Names the table and, when the rebuild loses or alters values, the columns (table.column), never a value.
AUTHOR
DBIO Authors
COPYRIGHT AND LICENSE
Copyright (C) 2026 DBIO Authors
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.