Qore Schema Module Reference 1.4.2
Loading...
Searching...
No Matches
Schema.qm.dox.h
1// -*- mode: c++; indent-tabs-mode: nil -*-
3
4/* Schema.qm Copyright 2014 - 2024 Qore Technologies, s.r.o.
5
6 Permission is hereby granted, free of charge, to any person obtaining a
7 copy of this software and associated documentation files (the "Software"),
8 to deal in the Software without restriction, including without limitation
9 the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 and/or sell copies of the Software, and to permit persons to whom the
11 Software is furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 DEALINGS IN THE SOFTWARE.
23*/
24
25// minimum Qore version
26
27// requires the SqlUtil module
28
29// requires the Util module
30
31// don't use "$" signs for variables and class members, assume local variable scope
32
33// require type definitions everywhere
34
35// enable all warnings
36
37// strict args
38
39
117namespace Schema {
119 const C_NULL = False;
121 const C_NOT_NULL = True;
122
124
132 hash<GenericColumnInfo> c_int(bool notnull = False, *string comment);
133
134
136
142 hash<GenericColumnInfo> c_int(string comment);
143
144
146
151 hash<GenericColumnInfo> c_varchar(int size, bool notnull = False, *string comment);
152
153
155
158 hash<GenericColumnInfo> c_varchar(int size, string comment);
159
160
162
167 hash<GenericColumnInfo> c_char(int size, bool notnull = False, *string comment);
168
169
171
174 hash<GenericColumnInfo> c_char(int size, string comment);
175
176
178
184 hash<GenericColumnInfo> c_date(bool notnull = False, *string comment);
185
186
188
192 hash<GenericColumnInfo> c_date(string comment);
193
194
196
202 hash<GenericColumnInfo> c_timestamp(bool notnull = False, *string comment);
203
204
206
210 hash<GenericColumnInfo> c_timestamp(string comment);
211
212
214
221 hash<GenericColumnInfo> c_number(bool notnull = False, *string comment);
222
223
225
233 hash<GenericColumnInfo> c_number(int size, int scale, bool notnull = False, *string comment);
234
235
237
244 hash<GenericColumnInfo> c_number(int size, bool notnull = False, *string comment);
245
246
248
253 hash<GenericColumnInfo> c_number(int size, string comment);
254
255
257
263 hash<GenericColumnInfo> c_blob(bool notnull = False, *string comment);
264
265
267
271 hash<GenericColumnInfo> c_blob(string comment);
272
273
275
281 hash<GenericColumnInfo> c_clob(bool notnull = False, *string comment);
282
283
285
289 hash<GenericColumnInfo> c_clob(string comment);
290
291
293 public hashdecl SchemaAlignmentInfo {
295
298
301
303 *hash<string, int> change_map;
304
306 *hash<string, int> data_change_map;
307 };
308
311
312public:
313 AbstractSchema schema;
314 int verbose;
315 int change_count = 0;
316 int dot_count = 0;
317 int error_count = 0;
318
319 list<string> sql_cache = ();
320
322 hash<string, int> change_map;
323
325 hash<string, int> data_change_map;
326
328
331
333 const CreateActionMap = ...;
334
335
337
341
342
344 hash<SchemaAlignmentInfo> getInfo();
345
346
348 infoCallback(string str, int ac, *string type, *string name, *string table, *string new_name, *string info);
349
350
352 sqlCallback(string str);
353
354
356 nothing sqlForceCallback(string str);
357
358
360 hash<auto> getCallbacks(bool force = False);
361
362 };
363
365 public hashdecl SchemaOptionInfo {
367 *string data_ts;
368
370 *string index_ts;
371
373 *hash<auto> db_opts;
374 };
375
377
410
411public:
412protected:
414 string name;
416 string version;
417
419 hash schema;
420
429
433 string drv;
434
437
442
445
447 *string data_ts;
448
450 *string index_ts;
451
452public:
453
455
460 constructor(Qore::SQL::AbstractDatasource ds, *string dts, *string its, *hash opts);
461
462
464
469 constructor(Qore::SQL::AbstractDatasource ds, *hash<SchemaOptionInfo> opts);
470
471
473 string getName();
474
475
477 string getVersion();
478
479
482
483
486
487
489
491 logpf(string fmt, ...);
492
493
495
497 log(string fmt, ...);
498
499
501
503 logProgress(string str);
504
505
507
519 int align(bool force = False, int verbose = 0, bool do_msgs = True);
520
521
523
535 hash<SchemaAlignmentInfo> alignWithInfo(bool force = False, int verbose = 0, bool do_msgs = True);
536
537
539
551protected:
552 SchemaCallbackHelper alignIntern(bool force = False, int verbose = 0, bool do_msgs = True);
553public:
554
555
557 drop(bool force = False, int verbose = 0, bool do_msgs = True);
558
559
561
565 *hash<auto> getIndexOptions();
566
567
569
573 *hash<auto> getCreationOptions();
574
575
577
580 *hash<auto> getColumnOptions();
581
582
584
587 *hash<auto> getTables();
588
589
591
594 *hash<auto> getSequences();
595
596
598
601 *hash<auto> getTypes();
602
603
605
608 *hash<auto> getFunctions();
609
610
612
615 *hash<auto> getProcedures();
616
617
619
622 *hash<auto> getPackages();
623
624
626
629 *hash<auto> getMaterializedViews();
630
631
633
637
638
640
643 *hash<auto> getReferenceDataHash();
644
645
647
651
652
654
658
659
661protected:
662 init(Qore::SQL::AbstractDatasource ds, *hash<SchemaOptionInfo> opts);
663public:
664
665
667protected:
668 abstract string getNameImpl();
669public:
670
672protected:
673 abstract string getVersionImpl();
674public:
675
677
679protected:
680 *hash<auto> getIndexOptionsImpl();
681public:
682
683
685
687protected:
688 *hash<auto> getColumnOptionsImpl();
689public:
690
691
693
695protected:
697public:
698
699
701
703protected:
704 *hash<auto> getTablesImpl();
705public:
706
707
709
711protected:
712 *hash<auto> getSequencesImpl();
713public:
714
715
717
719protected:
720 *hash<auto> getTypesImpl();
721public:
722
723
725
727protected:
728 *hash<auto> getFunctionsImpl();
729public:
730
731
733
735protected:
736 *hash<auto> getProceduresImpl();
737public:
738
739
741
743protected:
744 *hash<auto> getPackagesImpl();
745public:
746
747
749
751protected:
753public:
754
755
757
759protected:
761public:
762
763
765
767protected:
769public:
770
771
773
775protected:
777public:
778
779
781
783protected:
785public:
786
787
789
792protected:
794public:
795
796
798protected:
800public:
801
802
804protected:
805 bool checkDropSchema(bool force);
806public:
807
808
810protected:
811 bool checkUpdateSchema(bool force, reference<hash<auto>> initial_schema_info);
812public:
813
814
816protected:
817 doPostAlignment(Tables table_cache, bool first_time_install, *hash<auto> initial_schema_info, int verbose);
818public:
819
820
822protected:
823 doPostAlignment(Tables table_cache, bool first_time_install, *hash<auto> initial_schema_info);
824public:
825
826
828protected:
829 int getUpsertStrategy(bool first_time_install);
830public:
831
832
834protected:
835 postDataActions(Tables table_cache, bool first_time_install, *hash<auto> initial_schema_info, int verbose);
836public:
837
838
840protected:
841 postDataActions(bool first_time_install);
842public:
843
844
846protected:
847 doTable(AbstractTable table, list rows, int upsert_strategy, bool delete_others, int verbose, reference<hash<string, int>> sh);
848public:
849
850
852
854 static list getRows(*softlist<auto> l);
855
857 static hash combineOptions(*hash h);
858 };
859
861
871
872public:
873protected:
880
881public:
882
884
889 constructor(Qore::SQL::AbstractDatasource ds, *string dts, *string its, *hash opts) ;
890
891
893protected:
894 *softstring getSchemaVersion();
895public:
896
897
899protected:
900 bool checkDropSchema(bool force);
901public:
902
903
905protected:
906 bool checkUpdateSchema(bool force, reference<hash<auto>> initial_schema_info);
907public:
908
909
911protected:
912 bool checkUpgrade(string current_version);
913public:
914
915
917protected:
918 bool checkDowngrade(string current_version);
919public:
920
921
923
926protected:
928public:
929
930
932
935protected:
937public:
938
939
941
944protected:
946public:
947
948
950protected:
951 abstract string getVersionTableImpl();
952public:
953
955protected:
956 abstract string getVersionColumnImpl();
957public:
958
960protected:
961 abstract hash getVersionWhereImpl();
962public:
963 };
964};
the AbstractSchema class is a base class to assist with automatic schema management
Definition Schema.qm.dox.h:409
doPostAlignment(Tables table_cache, bool first_time_install, *hash< auto > initial_schema_info, int verbose)
this method is called after schema structural alignment has been executed but before schema reference...
doPostAlignment(Tables table_cache, bool first_time_install, *hash< auto > initial_schema_info)
this method is called after schema structural alignment has been executed but before schema reference...
hash schema
the schema template, as assembled from method callbacks providing schema element definitions
Definition Schema.qm.dox.h:419
string getVersion()
returns the version of the schema
constructor(Qore::SQL::AbstractDatasource ds, *hash< SchemaOptionInfo > opts)
creates the object from the arguments
*hash< auto > getTablesImpl()
returns table definitions
hash callback_opts
callback options plus all options
Definition Schema.qm.dox.h:441
string drv
the name of the database driver
Definition Schema.qm.dox.h:433
abstract string getNameImpl()
returns the name of the schema
static list getRows(*softlist< auto > l)
returns a list of hashes from a list of lists where the first list element in the top-level list is a...
*hash< auto > getPackages()
returns (Oracle) package definitions
SqlUtil::Database db
the Database object for the schema
Definition Schema.qm.dox.h:436
static hash combineOptions(*hash h)
combines option hashes into a single target option hash
doTable(AbstractTable table, list rows, int upsert_strategy, bool delete_others, int verbose, reference< hash< string, int > > sh)
this method is called to perform schema reference data managment on the given table with the given da...
*hash< auto > getMaterializedViewsImpl()
returns materialized view definitions
*hash< auto > getReferenceDataHashImpl()
returns a hash of "normal reference data", describing data that must appear in the target table,...
Qore::SQL::AbstractDatasource ds
the datasource for the schema
Definition Schema.qm.dox.h:431
*string data_ts
explicit data tablespace name
Definition Schema.qm.dox.h:447
*hash< auto > getTypesImpl()
returns type definitions
*hash< auto > getMaterializedViews()
returns materialized view definitions
constructor(Qore::SQL::AbstractDatasource ds, *string dts, *string its, *hash opts)
creates the object from the arguments
postDataActions(Tables table_cache, bool first_time_install, *hash< auto > initial_schema_info, int verbose)
this method is called after schema reference data has been managed
*hash creation_options
creation options, as provided by getCreationOptions()
Definition Schema.qm.dox.h:424
*hash< auto > getReferenceDataHash()
returns a hash of "normal reference data", describing data that must appear in the target table,...
int align(bool force=False, int verbose=0, bool do_msgs=True)
executes a schema alignment action on the database with the current schema template
*hash< auto > getFunctionsImpl()
returns function definitions
bool checkDropSchema(bool force)
this method returns True if the schema can be dropped
*hash< auto > getTables()
returns table definitions
hash< SchemaAlignmentInfo > alignWithInfo(bool force=False, int verbose=0, bool do_msgs=True)
executes a schema alignment action on the database with the current schema template
*hash< auto > getTypes()
returns type definitions
*hash< auto > getGenericOptionsImpl()
returns schema creation options
*hash< auto > getProcedures()
returns stored procedure definitions
hash pure_callback_opts
just callback options
Definition Schema.qm.dox.h:439
init(Qore::SQL::AbstractDatasource ds, *hash< SchemaOptionInfo > opts)
shared constructor initialization
*hash column_options
column options, as provided by getColumnOptions()
Definition Schema.qm.dox.h:426
code info_callback
the info callback for schema operations; can be used for explicit logging
Definition Schema.qm.dox.h:444
*hash< auto > getCreateOnlyReferenceData()
returns a hash of "create-only reference data", describing data that is written to the table when the...
*string index_ts
explicit index tablespace name
Definition Schema.qm.dox.h:450
*hash< auto > getCreationOptions()
returns schema creation options
string version
the version of the schema
Definition Schema.qm.dox.h:416
postDataActions(bool first_time_install)
this method is called after schema reference data has been managed
*hash< auto > getColumnOptionsImpl()
returns column options
Qore::SQL::AbstractDatasource getDatasource()
returns the datasource used for the schema
int getUpsertStrategy(bool first_time_install)
this method is called to return the upsert strategy before schema reference data management
*hash index_options
index options, as provided by getIndexOptions()
Definition Schema.qm.dox.h:422
*hash< auto > getIndexOptions()
returns index options
bool checkFirstTimeInstall()
returns True if checkExistence() returns False
*hash< auto > getColumnOptions()
returns column options
*hash< auto > getProceduresImpl()
returns stored procedure definitions
*hash< auto > getIndexOptionsImpl()
returns index options
*hash< auto > getPackagesImpl()
returns (Oracle) package definitions
abstract string getVersionImpl()
returns the version of the schema
SqlUtil::AbstractDatabase getDatabase()
returns the AbstractDatabase object used for the schema
*hash< auto > getFunctions()
returns function definitions
bool checkExistence()
returns True if the method can detect that DB objects defined in the schema exist in the database
*hash< auto > getInsertOnlyReferenceDataImpl()
returns a hash of "insert-only reference data", describing data that will only be inserted if missing...
string getName()
returns the name of the schema
*hash< auto > getCreateOnlyReferenceDataImpl()
returns a hash of "create-only reference data", describing data that is written to the table when the...
*hash all_options
combined creation and column options
Definition Schema.qm.dox.h:428
*hash< auto > getInsertOnlyReferenceData()
returns a hash of "create-only reference data", describing data that will only be inserted if missing...
*hash< auto > getSequences()
returns sequence definitions
string name
the name of the schema
Definition Schema.qm.dox.h:414
*hash< auto > getSequencesImpl()
returns sequence definitions
SchemaCallbackHelper alignIntern(bool force=False, int verbose=0, bool do_msgs=True)
executes a schema alignment action on the database with the current schema template
drop(bool force=False, int verbose=0, bool do_msgs=True)
executes a schema drop operation in the database
*hash< auto > getStrictReferenceDataHashImpl()
returns a hash of "strict reference data", describing the only data that can appear in the target tab...
*hash< auto > getStrictReferenceDataHash()
returns a hash of "strict reference data", describing the only data that can appear in the target tab...
logProgress(string str)
outputs a log message without any newline
log(string fmt,...)
outputs a log message
logpf(string fmt,...)
outputs a log message prefixed with the schema name
bool checkUpdateSchema(bool force, reference< hash< auto > > initial_schema_info)
this method returns True if the schema can be updated
this class extends Schema::AbstractSchema by providing version logic based on a schema version string...
Definition Schema.qm.dox.h:870
bool checkDowngrade(string current_version)
this method is called if the current schema version is greater than the target version; returns True ...
string version_column
the name of the column containing the version string
Definition Schema.qm.dox.h:877
string getVersionTable()
returns the name of the table holding the schema version string by calling getVersionTableImpl()
abstract hash getVersionWhereImpl()
returns the where clause hash defining the row where the schema version string is located
bool checkUpdateSchema(bool force, reference< hash< auto > > initial_schema_info)
this method returns True if the schema can be updated
abstract string getVersionColumnImpl()
returns the name of the column holding the schema version string
string getVersionColumn()
returns the name of the column holding the schema version string by calling getVersionColumnImpl()
*softstring getSchemaVersion()
returns the existing schema version or NOTHING if not present
hash getVersionWhere()
returns the where clause hash defining the row where the schema version string is located by calling ...
bool checkUpgrade(string current_version)
this method is called if the current schema version is less than the target version; returns True if ...
hash version_where
a where clause hash defining the row where the schema version string is located
Definition Schema.qm.dox.h:879
abstract string getVersionTableImpl()
returns the name of the table holding the schema version string
constructor(Qore::SQL::AbstractDatasource ds, *string dts, *string its, *hash opts)
creates the object based on the arguments giving the location of the schema
bool checkDropSchema(bool force)
this method returns True if the schema can be dropped
string version_table
the name of the table containing the version string
Definition Schema.qm.dox.h:875
this class provides callback support for schema operations
Definition Schema.qm.dox.h:310
const CreateActionMap
Map of create actions.
Definition Schema.qm.dox.h:333
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
bool created
Set to True if only creations / additions were made.
Definition Schema.qm.dox.h:330
constructor(AbstractSchema sc, int v=0)
creates the callback object from the given arguments
nothing sqlForceCallback(string str)
this is the SQL callback method for forced schema operations
sqlCallback(string str)
this is the SQL callback method for schema operations
hash< string, int > change_map
Change map; action code -> count.
Definition Schema.qm.dox.h:322
hash< SchemaAlignmentInfo > getInfo()
Returns information about schema changes made.
hash< auto > getCallbacks(bool force=False)
returns a callback option hash usable with SqlUtil schema operations
hash< string, int > data_change_map
Summary map for data changes; upsert action code -> count.
Definition Schema.qm.dox.h:325
this namespace contains all public definitions in the Schema module
Definition Schema.qm.dox.h:117
hash< GenericColumnInfo > c_blob(bool notnull=False, *string comment)
returns a column hash for a BLOB column
hash< GenericColumnInfo > c_date(bool notnull=False, *string comment)
returns a column hash for a DATE column
hash< GenericColumnInfo > c_clob(bool notnull=False, *string comment)
returns a column hash for a CLOB column
hash< GenericColumnInfo > c_number(bool notnull=False, *string comment)
returns a column hash for a NUMBER or NUMERIC column
hash< GenericColumnInfo > c_timestamp(bool notnull=False, *string comment)
returns a column hash for a TIMESTAMP column
hash< GenericColumnInfo > c_varchar(int size, bool notnull=False, *string comment)
returns a column hash for a VARCHAR column
hash< GenericColumnInfo > c_char(int size, bool notnull=False, *string comment)
returns a column hash for a CHAR column
hash< GenericColumnInfo > c_int(bool notnull=False, *string comment)
returns a column hash for an INT column
const C_NULL
Helper constant for column hash functions with "NULL" constraint for better readability.
Definition Schema.qm.dox.h:119
const C_NOT_NULL
Helper constant for column hash functions with "NOT NULL" constraint for better readability.
Definition Schema.qm.dox.h:121
Provides information on schema changes.
Definition Schema.qm.dox.h:293
bool created
Set to True if only creations / additions were made.
Definition Schema.qm.dox.h:297
*hash< string, int > change_map
Change map; action code -> count.
Definition Schema.qm.dox.h:303
int num_changes
The total number of changes made.
Definition Schema.qm.dox.h:300
*hash< string, int > data_change_map
Summary map for data changes; upsert action code -> count.
Definition Schema.qm.dox.h:306
Schema option hash definitions.
Definition Schema.qm.dox.h:365
*string data_ts
explicit data tablespace name
Definition Schema.qm.dox.h:367
*hash< auto > db_opts
options for SqlUtil::Database::constructor()
Definition Schema.qm.dox.h:373
*string index_ts
explicit index tablespace name
Definition Schema.qm.dox.h:370