if (
self.dialect._support_default_function
and not re.match(r"^\s*[\'\"\(]", default)
- and "ON UPDATE" not in default
+ and not re.search(r"ON +UPDATE", default, re.I)
and re.match(r".*\W.*", default)
):
colspec.append(f"DEFAULT ({default})")
"description", String(255), server_default=func.lower("hi")
),
Column("data", JSON, server_default=func.json_object()),
+ Column(
+ "updated1",
+ DateTime,
+ server_default=text("now() on update now()"),
+ ),
+ Column(
+ "updated2",
+ DateTime,
+ server_default=text("now() On UpDate now()"),
+ ),
+ Column(
+ "updated3",
+ DateTime,
+ server_default=text("now() ON UPDATE now()"),
+ ),
)
eq_(dialect._support_default_function, has_brackets)
"time DATETIME DEFAULT CURRENT_TIMESTAMP, "
"name VARCHAR(255) DEFAULT 'some str', "
"description VARCHAR(255) DEFAULT (lower('hi')), "
- "data JSON DEFAULT (json_object()))",
+ "data JSON DEFAULT (json_object()), "
+ "updated1 DATETIME DEFAULT now() on update now(), "
+ "updated2 DATETIME DEFAULT now() On UpDate now(), "
+ "updated3 DATETIME DEFAULT now() ON UPDATE now())",
dialect=dialect,
)
else:
"time DATETIME DEFAULT CURRENT_TIMESTAMP, "
"name VARCHAR(255) DEFAULT 'some str', "
"description VARCHAR(255) DEFAULT lower('hi'), "
- "data JSON DEFAULT json_object())",
+ "data JSON DEFAULT json_object(), "
+ "updated1 DATETIME DEFAULT now() on update now(), "
+ "updated2 DATETIME DEFAULT now() On UpDate now(), "
+ "updated3 DATETIME DEFAULT now() ON UPDATE now())",
dialect=dialect,
)
class ServerDefaultCreateTest(fixtures.TestBase):
+ __only_on__ = "mysql", "mariadb"
+ __backend__ = True
+
@testing.combinations(
(Integer, text("10")),
(Integer, text("'10'")),
literal_column("3") + literal_column("5"),
testing.requires.mysql_expression_defaults,
),
+ (
+ DateTime,
+ text("now() ON UPDATE now()"),
+ ),
+ (
+ DateTime,
+ text("now() on update now()"),
+ ),
+ (
+ DateTime,
+ text("now() ON UPDATE now()"),
+ ),
argnames="datatype, default",
)
def test_create_server_defaults(