diff --git a/tests/constraints/default.cpp b/tests/constraints/default.cpp index e59c63ee0..d35c3347c 100644 --- a/tests/constraints/default.cpp +++ b/tests/constraints/default.cpp @@ -71,3 +71,32 @@ TEST_CASE("default value for string") { make_column("phone", &Contact::phone))); storage.sync_schema(); } + +TEST_CASE("default current time/date/timestamp") { + struct User { + int id = 0; + std::string current; + }; + SECTION("time") { + auto storage = make_storage({}, + make_table("users", + make_column("id", &User::id, primary_key()), + make_column("current", &User::current, default_value(current_time())))); + storage.sync_schema(); + } + SECTION("date") { + auto storage = make_storage({}, + make_table("users", + make_column("id", &User::id, primary_key()), + make_column("current", &User::current, default_value(current_date())))); + storage.sync_schema(); + } + SECTION("timestamp") { + auto storage = + make_storage({}, + make_table("users", + make_column("id", &User::id, primary_key()), + make_column("current", &User::current, default_value(current_timestamp())))); + storage.sync_schema(); + } +} diff --git a/tests/statement_serializer_tests/schema/column.cpp b/tests/statement_serializer_tests/schema/column.cpp index 4e27fc710..1ed77849e 100644 --- a/tests/statement_serializer_tests/schema/column.cpp +++ b/tests/statement_serializer_tests/schema/column.cpp @@ -60,6 +60,26 @@ TEST_CASE("statement_serializer column") { value = serialize(column, context); expected = "\"nullable_text\" TEXT NULL"; } + // default + SECTION("default") { + SECTION("current") { + SECTION("time") { + auto column = make_column("name", &User::name, default_value(current_time())); + value = serialize(column, context); + expected = "\"name\" TEXT DEFAULT (CURRENT_TIME) NOT NULL"; + } + SECTION("date") { + auto column = make_column("name", &User::name, default_value(current_date())); + value = serialize(column, context); + expected = "\"name\" TEXT DEFAULT (CURRENT_DATE) NOT NULL"; + } + SECTION("timestamp") { + auto column = make_column("name", &User::name, default_value(current_timestamp())); + value = serialize(column, context); + expected = "\"name\" TEXT DEFAULT (CURRENT_TIMESTAMP) NOT NULL"; + } + } + } } SECTION("without types and constraints") { context.skip_types_and_constraints = true;