Lightweight 0.20260303.0
Loading...
Searching...
No Matches
Folder.hpp
1// SPDX-License-Identifier: Apache-2.0
2
3#pragma once
4
5#include "../Api.hpp"
6#include "../SqlMigration.hpp"
7
8#include <optional>
9#include <string_view>
10
11namespace Lightweight::MigrationFold
12{
13
14/// @brief Re-export of `SqlMigration::MigrationManager::PlanFoldingResult` so callers
15/// in this namespace can use a shorter spelling.
16using FoldResult = SqlMigration::MigrationManager::PlanFoldingResult;
17
18/// @brief Resolves an `--up-to <X>` argument to a `MigrationTimestamp`. Accepts:
19///
20/// - The empty string → latest registered release. Throws if no releases exist.
21/// - All-digit strings → parsed as a raw timestamp.
22/// - Anything else → looked up as a release version. Throws if unknown.
23///
24/// Centralised here so the dbtool command and any future caller resolve `--up-to`
25/// identically.
26[[nodiscard]] LIGHTWEIGHT_API SqlMigration::MigrationTimestamp ResolveUpTo(SqlMigration::MigrationManager const& manager,
27 std::string_view raw);
28
29/// @brief Folds the given manager's migrations up to (optionally) `upToInclusive`,
30/// using the supplied formatter to build the per-migration plans. Wrapper around
31/// `MigrationManager::FoldRegisteredMigrations`.
32[[nodiscard]] LIGHTWEIGHT_API FoldResult Fold(SqlMigration::MigrationManager const& manager,
33 SqlQueryFormatter const& formatter,
34 std::optional<SqlMigration::MigrationTimestamp> upToInclusive = std::nullopt);
35
36} // namespace Lightweight::MigrationFold