ensure proper table creation in session::create_schema including foreign key constraints

This commit is contained in:
Sascha Kühl
2025-07-17 15:56:15 +02:00
parent 581b93c5ea
commit fa393a1e30
16 changed files with 186 additions and 221 deletions
+62 -62
View File
@@ -131,14 +131,14 @@ int main() {
// logger::default_min_log_level(logger::log_level::LVL_DEBUG);
// logger::add_log_sink(logger::create_stdout_sink());
// {
// // has_many with builtin-type
// object::schema schema;
//
// auto result = schema.attach<names>("names");
//
// schema.dump(std::cout);
// }
{
// has_many with builtin-type
object::schema schema;
auto result = schema.attach<names>("names");
schema.dump(std::cout);
}
{
// has_many with foreign without belongs_to
object::schema schema;
@@ -157,58 +157,58 @@ int main() {
schema.dump(std::cout);
}
// {
// // has_many to belongs_to
// object::schema schema;
//
// auto result = schema.attach<author>("authors")
// .and_then([&schema] { return schema.attach<book>("books"); });
//
// schema.dump(std::cout);
// }
// {
// // belongs_to to has_many
// object::schema schema;
//
// auto result = schema.attach<book>("books")
// .and_then([&schema] { return schema.attach<author>("authors"); });
//
// schema.dump(std::cout);
// }
// {
// // has_many_to_many (with join columns first)
// object::schema schema;
//
// auto result = schema.attach<demo::ingredient>("ingredients")
// .and_then([&schema] { return schema.attach<recipe>("recipes"); });
//
// schema.dump(std::cout);
// }
// {
// // has_many_to_many (with join columns last)
// object::schema schema;
//
// auto result = schema.attach<demo::recipe>("recipes")
// .and_then([&schema] { return schema.attach<ingredient>("ingredients"); });
//
// schema.dump(std::cout);
// }
// {
// // belongs_to to has_one
// object::schema schema;
//
// auto result = schema.attach<profile>("profiles")
// .and_then([&schema] { return schema.attach<user>("users"); });
//
// schema.dump(std::cout);
// }
// {
// // has_one to belongs_to
// object::schema schema;
//
// auto result = schema.attach<user>("users")
// .and_then([&schema] { return schema.attach<profile>("profiles"); });
//
// schema.dump(std::cout);
// }
{
// has_many to belongs_to
object::schema schema;
auto result = schema.attach<author>("authors")
.and_then([&schema] { return schema.attach<book>("books"); });
schema.dump(std::cout);
}
{
// belongs_to to has_many
object::schema schema;
auto result = schema.attach<book>("books")
.and_then([&schema] { return schema.attach<author>("authors"); });
schema.dump(std::cout);
}
{
// has_many_to_many (with join columns first)
object::schema schema;
auto result = schema.attach<demo::ingredient>("ingredients")
.and_then([&schema] { return schema.attach<recipe>("recipes"); });
schema.dump(std::cout);
}
{
// has_many_to_many (with join columns last)
object::schema schema;
auto result = schema.attach<demo::recipe>("recipes")
.and_then([&schema] { return schema.attach<ingredient>("ingredients"); });
schema.dump(std::cout);
}
{
// belongs_to to has_one
object::schema schema;
auto result = schema.attach<profile>("profiles")
.and_then([&schema] { return schema.attach<user>("users"); });
schema.dump(std::cout);
}
{
// has_one to belongs_to
object::schema schema;
auto result = schema.attach<user>("users")
.and_then([&schema] { return schema.attach<profile>("profiles"); });
schema.dump(std::cout);
}
}
+2 -2
View File
@@ -75,8 +75,8 @@ int main() {
const object::schema schema("Administration");
// sql::connection_pool<sql::connection> pool("postgres://news:news@127.0.0.1:15432/matador", 4);
sql::connection_pool<sql::connection> pool("postgres://test:test123!@127.0.0.1:5432/matador", 4);
sql::connection_pool<sql::connection> pool("postgres://news:news@127.0.0.1:15432/matador", 4);
// sql::connection_pool<sql::connection> pool("postgres://test:test123!@127.0.0.1:5432/matador", 4);
orm::session ses(pool);