76 return {
"BIGSERIAL PRIMARY KEY",
"EXTRACT(EPOCH FROM NOW())::BIGINT",
"TRUE",
"FALSE",
"INSERT INTO",
true};
79 "BIGINT AUTO_INCREMENT PRIMARY KEY",
"(UNIX_TIMESTAMP())",
"TRUE",
"FALSE",
"INSERT IGNORE INTO",
false};
83 "INTEGER PRIMARY KEY AUTOINCREMENT",
"(strftime('%s','now'))",
"1",
"0",
"INSERT OR IGNORE INTO",
false};
97 static constexpr std::string_view
NameChars =
"ABCDEFGHIJKLMNOPQRSTUVWXYZ_";
98 static constexpr std::string_view
ConflictToken =
"ON_CONFLICT(";
111 if (
args != std::string_view::npos &&
sql[
args] ==
')')
130 else if (
token ==
"NOW")
134 else if (
token ==
"TRUE")
138 else if (
token ==
"FALSE")
142 else if (
token ==
"INSERT_IF_ABSENT")
148 if (
dialect.NeedsConflictClause)
155 return std::unexpected(
Error::Invalid(std::format(
"unknown migration placeholder @{}@",
token)));
170 static constexpr std::string_view
Blanks =
" \t\r\n";
175 if (
begin != std::string::npos)
183 for (
size_t i = 0;
i <
sql.size(); ++
i)
185 const char c =
sql[
i];
192 else if (
c ==
'-' &&
i + 1 <
sql.size() &&
sql[
i + 1] ==
'-')
194 while (
i <
sql.size() &&
sql[
i] !=
'\n')
std::optional< int > ParseMigrationVersion(std::string_view filename)
Result< std::string > ResolveDialect(std::string_view sql, Driver driver)
static std::string ReadFile(const std::filesystem::path &path)
std::vector< std::string > SplitStatements(std::string_view sql)
std::expected< T, Error > Result
Dialect DialectFor(Driver driver)
The DDL spellings the three drivers disagree on, one per migration placeholder.
std::string_view EpochNow
@NOW@
std::string_view AutoIncrementKey
@ID@
std::string_view False
@FALSE@
std::string_view True
@TRUE@
std::string_view InsertIfAbsent
@INSERT_IF_ABSENT@
static Error Invalid(std::string detail)
int CurrentVersion
Max version recorded in the history table after the run.
int Applied
Migrations applied by this run.