All Classes Namespaces Functions Variables Groups Pages
Schema.qm.dox.h
// -*- mode: c++; indent-tabs-mode: nil -*-
// @file Schema.qm Qore user module for working with SQL data
/* Schema.qm Copyright 2014 - 2017 Qore Technologies, s.r.o.
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
*/
// this module requires Qore 0.8.13 or better
// requires the SqlUtil module
// requires the Util module
// don't use "$" signs for variables and class members, assume local variable scope
// require type definitions everywhere
// enable all warnings
// strict args
namespace Schema {
const C_NULL = False;
const C_NOT_NULL = True;
hash<GenericColumnInfo> c_int(bool notnull = False, *string comment);
hash<GenericColumnInfo> c_int(string comment);
hash<GenericColumnInfo> c_varchar(int size, bool notnull = False, *string comment);
hash<GenericColumnInfo> c_varchar(int size, string comment);
hash<GenericColumnInfo> c_char(int size, bool notnull = False, *string comment);
hash<GenericColumnInfo> c_char(int size, string comment);
hash<GenericColumnInfo> c_date(bool notnull = False, *string comment);
hash<GenericColumnInfo> c_date(string comment);
hash<GenericColumnInfo> c_timestamp(bool notnull = False, *string comment);
hash<GenericColumnInfo> c_timestamp(string comment);
hash<GenericColumnInfo> c_number(bool notnull = False, *string comment);
hash<GenericColumnInfo> c_number(int size, int scale, bool notnull = False, *string comment);
hash<GenericColumnInfo> c_number(int size, bool notnull = False, *string comment);
hash<GenericColumnInfo> c_number(int size, string comment);
hash<GenericColumnInfo> c_blob(bool notnull = False, *string comment);
hash<GenericColumnInfo> c_blob(string comment);
hash<GenericColumnInfo> c_clob(bool notnull = False, *string comment);
hash<GenericColumnInfo> c_clob(string comment);
class SchemaCallbackHelper {
public:
public :
AbstractSchema schema;
int verbose;
int change_count = 0;
int dot_count = 0;
int error_count = 0;
list sql_cache = ();
public:
constructor(AbstractSchema sc, int v = 0);
infoCallback(string str, int ac, *string type, *string name, *string table, *string new_name, *string info);
sqlCallback(string str);
nothing sqlForceCallback(string str);
hash getCallbacks(bool force = False);
};
class AbstractSchema {
public:
private :
string name;
string version;
hash schema;
*hash index_options;
*hash creation_options;
*hash column_options;
*hash all_options;
Qore::SQL::AbstractDatasource ds;
string drv;
SqlUtil::Database db;
hash pure_callback_opts;
hash callback_opts;
code info_callback;
*string data_ts;
*string index_ts;
public:
constructor(Qore::SQL::AbstractDatasource n_ds, *string dts, *string its, *hash opts);
string getName();
string getVersion();
Qore::SQL::AbstractDatasource getDatasource();
SqlUtil::AbstractDatabase getDatabase();
logpf(string fmt);
log(string fmt);
logProgress(string str);
int align(bool force = False, int verbose = 0);
drop(bool force = False, int verbose = 0);
*hash getIndexOptions();
*hash getCreationOptions();
*hash getColumnOptions();
*hash getTables();
*hash getSequences();
*hash getTypes();
*hash getFunctions();
*hash getProcedures();
*hash getPackages();
*hash getMaterializedViews();
*hash getStrictReferenceDataHash();
*hash getReferenceDataHash();
*hash getCreateOnlyReferenceData();
*hash getInsertOnlyReferenceData();
private:
abstract string getNameImpl();
public:
private:
abstract string getVersionImpl();
public:
private:
*hash getIndexOptionsImpl();
public:
private:
*hash getColumnOptionsImpl();
public:
private:
*hash getGenericOptionsImpl();
public:
private:
*hash getTablesImpl();
public:
private:
*hash getSequencesImpl();
public:
private:
*hash getTypesImpl();
public:
private:
*hash getFunctionsImpl();
public:
private:
*hash getProceduresImpl();
public:
private:
*hash getPackagesImpl();
public:
private:
*hash getMaterializedViewsImpl();
public:
private:
*hash getStrictReferenceDataHashImpl();
public:
private:
*hash getReferenceDataHashImpl();
public:
private:
*hash getCreateOnlyReferenceDataImpl();
public:
private:
*hash getInsertOnlyReferenceDataImpl();
public:
private:
bool checkExistence();
public:
private:
bool checkFirstTimeInstall();
public:
private:
bool checkDropSchema(bool force);
public:
private:
bool checkUpdateSchema(bool force, reference<hash> initial_schema_info);
public:
private:
doPostAlignment(Tables table_cache, bool first_time_install, *hash initial_schema_info);
public:
private:
int getUpsertStrategy(bool first_time_install);
public:
private:
postDataActions(bool first_time_install);
public:
private:
doTable(AbstractTable table, list rows, int upsert_strategy, bool delete_others, int verbose, reference<hash> sh);
public:
static list getRows(*softlist l);
static hash combineOptions(*hash h);
};
class AbstractVersionedSchema : public AbstractSchema {
public:
private :
string version_table;
string version_column;
hash version_where;
public:
constructor(Qore::SQL::AbstractDatasource ds, *string dts, *string its, *hash opts) ;
private:
*softstring getSchemaVersion();
public:
private:
bool checkDropSchema(bool force);
public:
private:
bool checkUpdateSchema(bool force, reference<hash> initial_schema_info);
public:
private:
bool checkUpgrade(string current_version);
public:
private:
bool checkDowngrade(string current_version);
public:
private:
string getVersionTable();
public:
private:
string getVersionColumn();
public:
private:
hash getVersionWhere();
public:
private:
abstract string getVersionTableImpl();
public:
private:
abstract string getVersionColumnImpl();
public:
private:
abstract hash getVersionWhereImpl();
public:
};
};
Schema::AbstractSchema::logProgress
logProgress(string str)
outputs a log message without any newline
Schema::AbstractSchema::getIndexOptions
*hash getIndexOptions()
returns index options
Schema::AbstractSchema::getProcedures
*hash getProcedures()
returns stored procedure definitions
Schema::AbstractSchema::ds
Qore::SQL::AbstractDatasource ds
the datasource for the schema
Definition: Schema.qm.dox.h:348
Schema::SchemaCallbackHelper::getCallbacks
hash getCallbacks(bool force=False)
returns a callback option hash usable with SqlUtil schema operations
Schema::SchemaCallbackHelper::infoCallback
infoCallback(string str, int ac, *string type, *string name, *string table, *string new_name, *string info)
this is the informational callback method for schema operations
Schema::AbstractSchema::getProceduresImpl
*hash getProceduresImpl()
returns stored procedure definitions
Schema::c_varchar
hash< GenericColumnInfo > c_varchar(int size, bool notnull=False, *string comment)
returns a column hash for a VARCHAR column
Schema::AbstractSchema::getInsertOnlyReferenceDataImpl
*hash getInsertOnlyReferenceDataImpl()
returns a hash of &quot;insert-only reference data&quot;, describing data that will only be inserted if missing...
Schema::AbstractSchema::getTablesImpl
*hash getTablesImpl()
returns table definitions
Schema::AbstractVersionedSchema::getVersionColumn
string getVersionColumn()
returns the name of the column holding the schema version string by calling getVersionColumnImpl() ...
Schema::AbstractSchema::name
string name
the name of the schema
Definition: Schema.qm.dox.h:331
Schema::AbstractSchema::getFunctionsImpl
*hash getFunctionsImpl()
returns function definitions
Schema::AbstractSchema::getSequences
*hash getSequences()
returns sequence definitions
Schema::AbstractSchema::doPostAlignment
doPostAlignment(Tables table_cache, bool first_time_install, *hash initial_schema_info)
this method is called after schema structural alignment has been executed but before schema reference...
Schema::c_clob
hash< GenericColumnInfo > c_clob(bool notnull=False, *string comment)
returns a column hash for a CLOB column
Schema::AbstractSchema::getMaterializedViewsImpl
*hash getMaterializedViewsImpl()
returns materialized view definitions
Schema::AbstractSchema::getVersion
string getVersion()
returns the version of the schema
True
const True
Schema::c_char
hash< GenericColumnInfo > c_char(int size, bool notnull=False, *string comment)
returns a column hash for a CHAR column
Schema::AbstractSchema::getTables
*hash getTables()
returns table definitions
Schema::AbstractSchema::column_options
*hash column_options
column options, as provided by getColumnOptions()
Definition: Schema.qm.dox.h:343
Schema::AbstractSchema::constructor
constructor(Qore::SQL::AbstractDatasource n_ds, *string dts, *string its, *hash opts)
creates the object from the arguments
Schema::AbstractSchema::getSequencesImpl
*hash getSequencesImpl()
returns sequence definitions
Schema::AbstractSchema::getReferenceDataHash
*hash getReferenceDataHash()
returns a hash of &quot;normal reference data&quot;, describing data that must appear in the target table...
Schema::AbstractSchema::getIndexOptionsImpl
*hash getIndexOptionsImpl()
returns index options
Schema::AbstractSchema::getColumnOptions
*hash getColumnOptions()
returns column options
Schema::AbstractVersionedSchema::checkDowngrade
bool checkDowngrade(string current_version)
this method is called if the current schema version is greater than the target version; returns True ...
Schema::AbstractVersionedSchema::getVersionWhere
hash getVersionWhere()
returns the where clause hash defining the row where the schema version string is located by calling ...
Schema::AbstractSchema::callback_opts
hash callback_opts
callback options plus all options
Definition: Schema.qm.dox.h:358
Schema::c_int
hash< GenericColumnInfo > c_int(bool notnull=False, *string comment)
returns a column hash for an INT column
Schema::AbstractSchema::align
int align(bool force=False, int verbose=0)
executes a schema alignment action on the database with the current schema template ...
SqlUtil::Database
Schema::AbstractSchema::getFunctions
*hash getFunctions()
returns function definitions
False
const False
Schema::c_blob
hash< GenericColumnInfo > c_blob(bool notnull=False, *string comment)
returns a column hash for a BLOB column
Qore::SQL::AbstractDatasource
Schema::AbstractVersionedSchema::getVersionTable
string getVersionTable()
returns the name of the table holding the schema version string by calling getVersionTableImpl() ...
list
list list(...)
Schema::AbstractSchema::index_options
*hash index_options
index options, as provided by getIndexOptions()
Definition: Schema.qm.dox.h:339
Schema::AbstractVersionedSchema::getSchemaVersion
*softstring getSchemaVersion()
returns the existing schema version or NOTHING if not present
Schema::AbstractSchema::getReferenceDataHashImpl
*hash getReferenceDataHashImpl()
returns a hash of &quot;normal reference data&quot;, describing data that must appear in the target table...
Schema::SchemaCallbackHelper::sqlCallback
sqlCallback(string str)
this is the SQL callback method for schema operations
Schema::AbstractVersionedSchema::version_column
string version_column
the name of the column containing the version string
Definition: Schema.qm.dox.h:752
Schema::AbstractVersionedSchema::checkUpgrade
bool checkUpgrade(string current_version)
this method is called if the current schema version is less than the target version; returns True if ...
Schema::AbstractSchema::getGenericOptionsImpl
*hash getGenericOptionsImpl()
returns schema creation options
Schema::AbstractSchema::getColumnOptionsImpl
*hash getColumnOptionsImpl()
returns column options
Schema::AbstractSchema::drop
drop(bool force=False, int verbose=0)
executes a schema drop operation in the database
Schema::AbstractSchema::data_ts
*string data_ts
explicit data tablespace name
Definition: Schema.qm.dox.h:364
Schema::AbstractSchema::getMaterializedViews
*hash getMaterializedViews()
returns materialized view definitions
Schema::c_timestamp
hash< GenericColumnInfo > c_timestamp(bool notnull=False, *string comment)
returns a column hash for a TIMESTAMP column
Schema::AbstractSchema::getUpsertStrategy
int getUpsertStrategy(bool first_time_install)
this method is called to return the upsert strategy before schema reference data management ...
Schema::c_number
hash< GenericColumnInfo > c_number(bool notnull=False, *string comment)
returns a column hash for a NUMBER or NUMERIC column
Schema::C_NULL
const C_NULL
Helper constant for column hash functions with &quot;NULL&quot; constraint for better readability.
Definition: Schema.qm.dox.h:92
Schema::AbstractSchema::doTable
doTable(AbstractTable table, list rows, int upsert_strategy, bool delete_others, int verbose, reference< hash > sh)
this method is called to perform schema reference data managment on the given table with the given da...
Schema::AbstractSchema::getDatabase
SqlUtil::AbstractDatabase getDatabase()
returns the AbstractDatabase object used for the schema
Schema::SchemaCallbackHelper::constructor
constructor(AbstractSchema sc, int v=0)
creates the callback object from the given arguments
Schema::AbstractSchema::log
log(string fmt)
outputs a log message
Schema::AbstractVersionedSchema::checkDropSchema
bool checkDropSchema(bool force)
this method returns True if the schema can be dropped
Schema::AbstractSchema::getCreateOnlyReferenceData
*hash getCreateOnlyReferenceData()
returns a hash of &quot;create-only reference data&quot;, describing data that is written to the table when the...
Schema::AbstractSchema::postDataActions
postDataActions(bool first_time_install)
this method is called after schema reference data has been managed
Schema::AbstractSchema::checkDropSchema
bool checkDropSchema(bool force)
this method returns True if the schema can be dropped
Schema::AbstractVersionedSchema
this class extends Schema::AbstractSchema by providing version logic based on a schema version string...
Definition: Schema.qm.dox.h:745
Schema::AbstractSchema::checkExistence
bool checkExistence()
returns True if the method can detect that DB objects defined in the schema exist in the database ...
Schema::AbstractVersionedSchema::constructor
constructor(Qore::SQL::AbstractDatasource ds, *string dts, *string its, *hash opts)
creates the object based on the arguments giving the location of the schema
Schema::AbstractSchema::creation_options
*hash creation_options
creation options, as provided by getCreationOptions()
Definition: Schema.qm.dox.h:341
Schema::AbstractSchema::schema
hash schema
the schema template, as assembled from method callbacks providing schema element definitions ...
Definition: Schema.qm.dox.h:336
Schema::SchemaCallbackHelper
this class provides callback support for schema operations
Definition: Schema.qm.dox.h:256
Schema::AbstractSchema::getStrictReferenceDataHash
*hash getStrictReferenceDataHash()
returns a hash of &quot;strict reference data&quot;, describing the only data that can appear in the target tab...
Schema::AbstractVersionedSchema::getVersionWhereImpl
abstract hash getVersionWhereImpl()
returns the where clause hash defining the row where the schema version string is located ...
Schema::AbstractSchema::getInsertOnlyReferenceData
*hash getInsertOnlyReferenceData()
returns a hash of &quot;create-only reference data&quot;, describing data that will only be inserted if missing...
Schema::AbstractSchema::getCreationOptions
*hash getCreationOptions()
returns schema creation options
type
string type(auto arg)
Schema::AbstractSchema::getRows
static list getRows(*softlist l)
returns a list of hashes from a list of lists where the first list element in the top-level list is a...
Schema::AbstractVersionedSchema::version_table
string version_table
the name of the table containing the version string
Definition: Schema.qm.dox.h:750
Schema::AbstractSchema::getTypes
*hash getTypes()
returns type definitions
Schema::AbstractSchema::getName
string getName()
returns the name of the schema
Schema::AbstractSchema::db
SqlUtil::Database db
the Database object for the schema
Definition: Schema.qm.dox.h:353
Schema::AbstractVersionedSchema::checkUpdateSchema
bool checkUpdateSchema(bool force, reference< hash > initial_schema_info)
this method returns True if the schema can be updated
Schema::AbstractSchema::info_callback
code info_callback
the info callback for schema operations; can be used for explicit logging
Definition: Schema.qm.dox.h:361
Schema::AbstractSchema::version
string version
the version of the schema
Definition: Schema.qm.dox.h:333
Schema::C_NOT_NULL
const C_NOT_NULL
Helper constant for column hash functions with &quot;NOT NULL&quot; constraint for better readability.
Definition: Schema.qm.dox.h:94
Schema::AbstractSchema::all_options
*hash all_options
combined creation and column options
Definition: Schema.qm.dox.h:345
Schema::AbstractSchema::getVersionImpl
abstract string getVersionImpl()
returns the version of the schema
Schema::AbstractSchema::drv
string drv
the name of the database driver
Definition: Schema.qm.dox.h:350
Schema::AbstractSchema::getCreateOnlyReferenceDataImpl
*hash getCreateOnlyReferenceDataImpl()
returns a hash of &quot;create-only reference data&quot;, describing data that is written to the table when the...
Schema::AbstractVersionedSchema::version_where
hash version_where
a where clause hash defining the row where the schema version string is located
Definition: Schema.qm.dox.h:754
Schema::c_date
hash< GenericColumnInfo > c_date(bool notnull=False, *string comment)
returns a column hash for a DATE column
Schema::AbstractSchema::logpf
logpf(string fmt)
outputs a log message prefixed with the schema name
Schema::AbstractSchema::getTypesImpl
*hash getTypesImpl()
returns type definitions
Schema::AbstractSchema::pure_callback_opts
hash pure_callback_opts
just callback options
Definition: Schema.qm.dox.h:356
Schema::AbstractSchema::getDatasource
Qore::SQL::AbstractDatasource getDatasource()
returns the datasource used for the schema
Schema::AbstractVersionedSchema::getVersionTableImpl
abstract string getVersionTableImpl()
returns the name of the table holding the schema version string
Schema::AbstractSchema::checkFirstTimeInstall
bool checkFirstTimeInstall()
returns True if checkExistence() returns False
hash
hash hash(object obj)
Schema::AbstractSchema::getNameImpl
abstract string getNameImpl()
returns the name of the schema
Schema::AbstractSchema::getPackagesImpl
*hash getPackagesImpl()
returns (Oracle) package definitions
Schema::AbstractSchema::getPackages
*hash getPackages()
returns (Oracle) package definitions
Schema::AbstractSchema::checkUpdateSchema
bool checkUpdateSchema(bool force, reference< hash > initial_schema_info)
this method returns True if the schema can be updated
SqlUtil::AbstractDatabase
Schema::AbstractSchema::index_ts
*string index_ts
explicit index tablespace name
Definition: Schema.qm.dox.h:367
Schema::SchemaCallbackHelper::sqlForceCallback
nothing sqlForceCallback(string str)
this is the SQL callback method for forced schema operations
Schema::AbstractSchema
the AbstractSchema class is a base class to assist with automatic schema management ...
Definition: Schema.qm.dox.h:326
Schema::AbstractSchema::getStrictReferenceDataHashImpl
*hash getStrictReferenceDataHashImpl()
returns a hash of &quot;strict reference data&quot;, describing the only data that can appear in the target tab...
Schema::AbstractSchema::combineOptions
static hash combineOptions(*hash h)
combines option hashes into a single target option hash
Schema::AbstractVersionedSchema::getVersionColumnImpl
abstract string getVersionColumnImpl()
returns the name of the column holding the schema version string