From d6de8da3c83e1cf9de76b6b30732267f71188476 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sascha=20K=C3=BChl?= Date: Thu, 13 Nov 2025 16:27:58 +0100 Subject: [PATCH] schema progress --- source/orm/orm/schema.cpp | 23 ++++++++++++----------- test/backends/SchemaTest.cpp | 2 +- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/source/orm/orm/schema.cpp b/source/orm/orm/schema.cpp index dc46e53..c9b824e 100644 --- a/source/orm/orm/schema.cpp +++ b/source/orm/orm/schema.cpp @@ -87,18 +87,19 @@ matador::utils::result matador::orm::schema::drop() drop_sql_commands.push_back(ctx.sql); // determine constraints and drop them for (auto it = node->info().endpoint_begin(); it != node->info().endpoint_end(); ++it) { - const auto ctx = query::query::alter() - .table( "" ) - .add_constraint( it->second->node().name() ) - .foreign_key( "" ) - .references( "" ).compile(*c); - + const auto& endpoint = *(it->second); + if (endpoint.type() == object::relation_type::BELONGS_TO) { + continue; + } + const auto drop_fk_ctx = query::query::alter() + .table( endpoint.node().name() ) + .drop_constraint( "FK_" + endpoint.node().name() + "_" + endpoint.foreign_endpoint()->field_name() ) + .compile(*c); + std::cout << drop_fk_ctx.sql << std::endl; + if (auto result = c->execute(drop_fk_ctx.sql); !result) { + return utils::failure(result.err()); + } } - // for ( const auto& [sql, command] : ctx.additional_commands ) { - // if (auto result = c->execute(ctx.sql); !result) { - // return utils::failure(result.err()); - // } - // } } // execute additional commands (e.g. ALTER TABLE ADD FK) diff --git a/test/backends/SchemaTest.cpp b/test/backends/SchemaTest.cpp index f8347a3..c284748 100644 --- a/test/backends/SchemaTest.cpp +++ b/test/backends/SchemaTest.cpp @@ -12,7 +12,7 @@ using namespace matador; using namespace matador::test; -TEST_CASE_METHOD(SchemaFixture, "Test schema", "[schema]") { +TEST_CASE_METHOD(SchemaFixture, "Test schema one-two-many", "[schema]") { using namespace matador::test; matador::orm::schema repo(pool/*, "NoopSchema"*/);