From b0c2c30dd0b83ea67fb2c8375ae2061dad0d1770 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 9 Apr 2013 16:17:27 +0200 Subject: Add support for embedded schema migration --- evolution/add-foreign-key/driver.cxx | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) (limited to 'evolution/add-foreign-key/driver.cxx') diff --git a/evolution/add-foreign-key/driver.cxx b/evolution/add-foreign-key/driver.cxx index 0d62889..26c1f57 100644 --- a/evolution/add-foreign-key/driver.cxx +++ b/evolution/add-foreign-key/driver.cxx @@ -11,7 +11,9 @@ #include #include +#include +#include // DATABASE_XXX #include #include "test1.hxx" @@ -27,7 +29,8 @@ main (int argc, char* argv[]) { try { - auto_ptr db (create_database (argc, argv)); + auto_ptr db (create_database (argc, argv, false)); + bool embedded (schema_catalog::exists (*db, "test2")); // 1 - base version // 2 - migration @@ -41,6 +44,15 @@ main (int argc, char* argv[]) { using namespace v2; + if (embedded) + { + transaction t (db->begin ()); + schema_catalog::create_schema (*db, "test2"); + schema_catalog::create_schema (*db, "test1"); + schema_catalog::migrate_schema (*db, 2, "test2"); + t.commit (); + } + object o (1); { @@ -54,6 +66,20 @@ main (int argc, char* argv[]) { using namespace v3; +#ifdef DATABASE_SQLITE + // In SQLite we can only add foreign keys inline in the column + // definition. + // + db->connection ()->execute ("PRAGMA foreign_keys=OFF"); +#endif + + if (embedded) + { + transaction t (db->begin ()); + schema_catalog::migrate_schema_pre (*db, 3, "test2"); + t.commit (); + } + // Both pointers are now NULL. // { @@ -83,6 +109,12 @@ main (int argc, char* argv[]) t.commit (); } + if (embedded) + { + transaction t (db->begin ()); + schema_catalog::migrate_schema_post (*db, 3, "test2"); + t.commit (); + } break; } case 3: @@ -113,6 +145,7 @@ main (int argc, char* argv[]) // As well as the NOT NULL. // +#ifndef DATABASE_SQLITE try { object o (3); @@ -123,6 +156,7 @@ main (int argc, char* argv[]) assert (false); } catch (const odb::exception& ) {} +#endif break; } default: -- cgit v1.1