Wappler Version : 7.1.2
Operating System : Win 11
Server Model: node
Database Type: PostgreSQL via docker
Hosting Type: DO/ Docker
Expected behavior
What do you think should happen?
Sub tables should be placed in correct position in heirachy
Actual behavior
What actually happens?
After inserting multiple sub tables, database manager starts to place tables incorrectly
How to reproduce
This is not a one off, i have been able to reproduce this in may ways by adding subtables in different places and under different names within the heirachy.
Firstly see this video to see scenario and lead up
Having made the video i started to think more about the issue and decided to investigate the knex files created.
The initial "content" add generated the following code:
exports.up = function(knex) {
return knex.schema
.raw(knex.client.constructor.name.startsWith('Client_PG') ? 'CREATE EXTENSION IF NOT EXISTS "uuid-ossp"' : 'SELECT 1')
.createTable('book_chapter_section_content', async function (table) {
table.uuid('content_id').primary().defaultTo(knex.client.constructor.name.startsWith('Client_PG') ? knex.raw('uuid_generate_v4()')
: (knex.client.constructor.name.includes('MSSQL') ? knex.raw('NEWID()')
: (knex.client.constructor.name.includes('MySQL') ? knex.raw('(UUID())') : null)));
table.uuid('section_id');
table.foreign('section_id').references('section_id').inTable('book_chapter_section').onUpdate('CASCADE').onDelete('CASCADE');
})
};
exports.down = function(knex) {
return knex.schema
.dropTable('book_chapter_section_content')
};
It can clearly be seen in the 4th and last line that the target is correctly:
book_chapter_section_content
However on examining the final (incorrect) commit the code was:
exports.up = function(knex) {
return knex.schema
.raw(knex.client.constructor.name.startsWith('Client_PG') ? 'CREATE EXTENSION IF NOT EXISTS "uuid-ossp"' : 'SELECT 1')
.createTable('subsection_content', async function (table) {
table.uuid('content_id').primary().defaultTo(knex.client.constructor.name.startsWith('Client_PG') ? knex.raw('uuid_generate_v4()')
: (knex.client.constructor.name.includes('MSSQL') ? knex.raw('NEWID()')
: (knex.client.constructor.name.includes('MySQL') ? knex.raw('(UUID())') : null)));
table.uuid('subsection_id');
table.foreign('subsection_id').references('subsection_id').inTable('book_chapter_section_subsection').onUpdate('CASCADE').onDelete('CASCADE');
})
};
exports.down = function(knex) {
return knex.schema
.dropTable('subsection_content')
};
The error can clearly be seen in that the fact that the parent table was itself a subtable of "section" has been misdiagnosed.
I was able to correct that issue by rolling back the change, and editing the two lines reading
"subsection_content"
to
"book_chapter_section_subsection_content"
Ironically the foreign key section appears correct
table.foreign('subsection_id').references('subsection_id').inTable('book_chapter_section_subsection').onUpdate('CASCADE').onDelete('CASCADE');
editing and quoting the full:
"book_chapter_section_subsection"
Seems to fix the issue.
I attach a zip file of the migrations leading up the the stage before the error so the structure can be rebuilt if necessary.
initial.zip (4.8 KB)
and a zip of the erroneous final migration
20250723120547_add more content.zip (615 Bytes)