Stroika Library 3.0d16
 
Loading...
Searching...
No Matches
Versioning.cpp
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2025. All rights reserved
3 */
4#include "Stroika/Foundation/StroikaPreComp.h"
5
7
8#include "Versioning.h"
9
10using namespace Stroika::Foundation;
12using namespace Stroika::Foundation::Database;
13using namespace Stroika::Foundation::Database::SQL;
14using namespace Stroika::Foundation::Debug;
15
16// Comment this in to turn on aggressive noisy DbgTrace in this module
17// #define USE_NOISY_TRACE_IN_THIS_MODULE_ 1
18
19/*
20 ********************************************************************************
21 *************************** ORM::ProvisionForVersion ***************************
22 ********************************************************************************
23 */
24void ORM::ProvisionForVersion (SQL::Connection::Ptr conn, Common::Version targetDBVersion, const Traversal::Iterable<Schema::Table>& tables)
25{
27 for (const auto& ti : tables) {
28 provisioners += TableProvisioner{
29 ti.fName, [=] (SQL::Connection::Ptr conn, optional<Common::Version> existingVersion, [[maybe_unused]] Common::Version targetDBVersion) -> void {
30 // properly upgrade - for now just create if doesn't exist
31 if (!existingVersion) {
32 conn.Exec (Schema::StandardSQLStatements{ti}.CreateTable ());
33 }
34 }};
35 }
36 ProvisionForVersion (conn, targetDBVersion, provisioners);
37}
38void ORM::ProvisionForVersion (SQL::Connection::Ptr conn, Common::Version targetDBVersion, const Traversal::Iterable<TableProvisioner>& tables)
39{
40 TraceContextBumper ctx{"ORM::ProvisionForVersion", "conn={}"_f, conn};
41 SQL::Statement doesTableExist = conn.mkStatement (conn.GetEngineProperties ()->GetSQL (SQL::EngineProperties::NonStandardSQL::eDoesTableExist));
42 for (const auto& ti : tables) {
43 doesTableExist.Reset ();
44 doesTableExist.Bind (SQL::EngineProperties::kDoesTableExistParameterName, ti.fTableName);
45 if (not doesTableExist.GetNextRow ()) {
46 ti.fProvisioner (conn, nullopt, targetDBVersion);
47 }
48 else {
49 // @todo store / pass along version
50 ti.fProvisioner (conn, Common::Version{1, 0, Common::VersionStage::Alpha, 0}, targetDBVersion);
51 }
52 }
53}
void ProvisionForVersion(SQL::Connection::Ptr conn, Common::Version targetDBVersion, const Traversal::Iterable< Schema::Table > &tables)
A Collection<T> is a container to manage an un-ordered collection of items, without equality defined ...
Definition Collection.h:102
nonvirtual shared_ptr< const EngineProperties > GetEngineProperties() const
nonvirtual void Reset()
resets the prepared statement back to the beginning of its program (this does NOT clear bindings)
Definition Statement.inl:52
nonvirtual optional< Row > GetNextRow()
Definition Statement.inl:58
Iterable<T> is a base class for containers which easily produce an Iterator<T> to traverse them.
Definition Iterable.h:237