Qore Schema Module Reference 1.4.1
Loading...
Searching...
No Matches
Schema.qm.dox.h
1// -*- mode: c++; indent-tabs-mode: nil -*-
3
4/* Schema.qm Copyright 2014 - 2023 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
113namespace Schema {
115 const C_NULL = False;
117 const C_NOT_NULL = True;
118
120
128 hash<GenericColumnInfo> c_int(bool notnull = False, *string comment);
129
130
132
138 hash<GenericColumnInfo> c_int(string comment);
139
140
142
147 hash<GenericColumnInfo> c_varchar(int size, bool notnull = False, *string comment);
148
149
151
154 hash<GenericColumnInfo> c_varchar(int size, string comment);
155
156
158
163 hash<GenericColumnInfo> c_char(int size, bool notnull = False, *string comment);
164
165
167
170 hash<GenericColumnInfo> c_char(int size, string comment);
171
172
174
180 hash<GenericColumnInfo> c_date(bool notnull = False, *string comment);
181
182
184
188 hash<GenericColumnInfo> c_date(string comment);
189
190
192
198 hash<GenericColumnInfo> c_timestamp(bool notnull = False, *string comment);
199
200
202
206 hash<GenericColumnInfo> c_timestamp(string comment);
207
208
210
217 hash<GenericColumnInfo> c_number(bool notnull = False, *string comment);
218
219
221
229 hash<GenericColumnInfo> c_number(int size, int scale, bool notnull = False, *string comment);
230
231
233
240 hash<GenericColumnInfo> c_number(int size, bool notnull = False, *string comment);
241
242
244
249 hash<GenericColumnInfo> c_number(int size, string comment);
250
251
253
259 hash<GenericColumnInfo> c_blob(bool notnull = False, *string comment);
260
261
263
267 hash<GenericColumnInfo> c_blob(string comment);
268
269
271
277 hash<GenericColumnInfo> c_clob(bool notnull = False, *string comment);
278
279
281
285 hash<GenericColumnInfo> c_clob(string comment);
286
287
289 public hashdecl SchemaAlignmentInfo {
291
294
297
299 *hash<string, int> change_map;
300
302 *hash<string, int> data_change_map;
303 };
304
307
308public:
309 AbstractSchema schema;
310 int verbose;
311 int change_count = 0;
312 int dot_count = 0;
313 int error_count = 0;
314
315 list<string> sql_cache = ();
316
318 hash<string, int> change_map;
319
321 hash<string, int> data_change_map;
322
324
327
330 AbstractDatabase::AC_Create: True,
331 AbstractDatabase::AC_Add: True,
332 AbstractDatabase::AC_Insert: True,
333 };
334
336
340
341
343 hash<SchemaAlignmentInfo> getInfo();
344
345
347 infoCallback(string str, int ac, *string type, *string name, *string table, *string new_name, *string info);
348
349
351 sqlCallback(string str);
352
353
355 nothing sqlForceCallback(string str);
356
357
359 hash<auto> getCallbacks(bool force = False);
360
361 };
362
364 public hashdecl SchemaOptionInfo {
366 *string data_ts;
367
369 *string index_ts;
370
372 *hash<auto> db_opts;
373 };
374
376
409
410public:
411protected:
413 string name;
415 string version;
416
418 hash schema;
419
428
432 string drv;
433
436
441
444
446 *string data_ts;
447
449 *string index_ts;
450
451public:
452
454
459 constructor(Qore::SQL::AbstractDatasource ds, *string dts, *string its, *hash opts);
460
461
463
468 constructor(Qore::SQL::AbstractDatasource ds, *hash<SchemaOptionInfo> opts);
469
470
472 string getName();
473
474
476 string getVersion();
477
478
481
482
485
486
488
490 logpf(string fmt);
491
492
494
496 log(string fmt);
497
498
500
502 logProgress(string str);
503
504
506
518 int align(bool force = False, int verbose = 0, bool do_msgs = True);
519
520
522
534 hash<SchemaAlignmentInfo> alignWithInfo(bool force = False, int verbose = 0, bool do_msgs = True);
535
536
538
550protected:
551 SchemaCallbackHelper alignIntern(bool force = False, int verbose = 0, bool do_msgs = True);
552public:
553
554
556 drop(bool force = False, int verbose = 0, bool do_msgs = True);
557
558
560
564 *hash<auto> getIndexOptions();
565
566
568
572 *hash<auto> getCreationOptions();
573
574
576
579 *hash<auto> getColumnOptions();
580
581
583
586 *hash<auto> getTables();
587
588
590
593 *hash<auto> getSequences();
594
595
597
600 *hash<auto> getTypes();
601
602
604
607 *hash<auto> getFunctions();
608
609
611
614 *hash<auto> getProcedures();
615
616
618
621 *hash<auto> getPackages();
622
623
625
628 *hash<auto> getMaterializedViews();
629
630
632
636
637
639
642 *hash<auto> getReferenceDataHash();
643
644
646
650
651
653
657
658
660protected:
661 init(Qore::SQL::AbstractDatasource ds, *hash<SchemaOptionInfo> opts);
662public:
663
664
666protected:
667 abstract string getNameImpl();
668public:
669
671protected:
672 abstract string getVersionImpl();
673public:
674
676
678protected:
679 *hash<auto> getIndexOptionsImpl();
680public:
681
682
684
686protected:
687 *hash<auto> getColumnOptionsImpl();
688public:
689
690
692
694protected:
696public:
697
698
700
702protected:
703 *hash<auto> getTablesImpl();
704public:
705
706
708
710protected:
711 *hash<auto> getSequencesImpl();
712public:
713
714
716
718protected:
719 *hash<auto> getTypesImpl();
720public:
721
722
724
726protected:
727 *hash<auto> getFunctionsImpl();
728public:
729
730
732
734protected:
735 *hash<auto> getProceduresImpl();
736public:
737
738
740
742protected:
743 *hash<auto> getPackagesImpl();
744public:
745
746
748
750protected:
752public:
753
754
756
758protected:
760public:
761
762
764
766protected:
768public:
769
770
772
774protected:
776public:
777
778
780
782protected:
784public:
785
786
788
791protected:
793public:
794
795
797protected:
799public:
800
801
803protected:
804 bool checkDropSchema(bool force);
805public:
806
807
809protected:
810 bool checkUpdateSchema(bool force, reference<hash<auto>> initial_schema_info);
811public:
812
813
815protected:
816 doPostAlignment(Tables table_cache, bool first_time_install, *hash<auto> initial_schema_info, int verbose);
817public:
818
819
821protected:
822 doPostAlignment(Tables table_cache, bool first_time_install, *hash<auto> initial_schema_info);
823public:
824
825
827protected:
828 int getUpsertStrategy(bool first_time_install);
829public:
830
831
833protected:
834 postDataActions(Tables table_cache, bool first_time_install, *hash<auto> initial_schema_info, int verbose);
835public:
836
837
839protected:
840 postDataActions(bool first_time_install);
841public:
842
843
845 private doTable(AbstractTable table, list rows, int upsert_strategy, bool delete_others, int verbose,
846 reference<hash<string, int>> sh) {
847 // if we are reporting the status, then change to "UpsertSelectFirst" so that we can only report updated rows
848 if (verbose > 0);
849
850
851 bool dot = False;
852
853 hash<string, int> tsh;
854 code cb = (string table_name, hash row, int result);
855;
856
857 table.upsertFromIterator(AbstractSchema::getRows(rows).iterator(), upsert_strategy, ("delete_others": delete_others, "info_callback": cb));
858
859 // show table summary if verbose = 1
860 if (verbose > 0);
861
862 }
863
865
867 static list getRows(*softlist<auto> l);
868
870 static hash combineOptions(*hash h);
871 };
872
874
884
885public:
886protected:
893
894public:
895
897
902 constructor(Qore::SQL::AbstractDatasource ds, *string dts, *string its, *hash opts) ;
903
904
906protected:
907 *softstring getSchemaVersion();
908public:
909
910
912protected:
913 bool checkDropSchema(bool force);
914public:
915
916
918protected:
919 bool checkUpdateSchema(bool force, reference<hash<auto>> initial_schema_info);
920public:
921
922
924protected:
925 bool checkUpgrade(string current_version);
926public:
927
928
930protected:
931 bool checkDowngrade(string current_version);
932public:
933
934
936
939protected:
941public:
942
943
945
948protected:
950public:
951
952
954
957protected:
959public:
960
961
963protected:
964 abstract string getVersionTableImpl();
965public:
966
968protected:
969 abstract string getVersionColumnImpl();
970public:
971
973protected:
974 abstract hash getVersionWhereImpl();
975public:
976 };
977};
the AbstractSchema class is a base class to assist with automatic schema management
Definition: Schema.qm.dox.h:408
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:418
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:440
string drv
the name of the database driver
Definition: Schema.qm.dox.h:432
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:435
static hash combineOptions(*hash h)
combines option hashes into a single target option hash
*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:430
*string data_ts
explicit data tablespace name
Definition: Schema.qm.dox.h:446
*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
logpf(string fmt)
outputs a log message prefixed with the schema name
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:423
*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
private 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...
Definition: Schema.qm.dox.h:845
hash pure_callback_opts
just callback options
Definition: Schema.qm.dox.h:438
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:425
code info_callback
the info callback for schema operations; can be used for explicit logging
Definition: Schema.qm.dox.h:443
*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:449
*hash< auto > getCreationOptions()
returns schema creation options
string version
the version of the schema
Definition: Schema.qm.dox.h:415
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:421
*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:427
*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:413
*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
bool checkUpdateSchema(bool force, reference< hash< auto > > initial_schema_info)
this method returns True if the schema can be updated
log(string fmt)
outputs a log message
this class extends Schema::AbstractSchema by providing version logic based on a schema version string...
Definition: Schema.qm.dox.h:883
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:890
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:892
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:888
this class provides callback support for schema operations
Definition: Schema.qm.dox.h:306
const CreateActionMap
Map of create actions.
Definition: Schema.qm.dox.h:329
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:326
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:318
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:321
this namespace contains all public definitions in the Schema module
Definition: Schema.qm.dox.h:113
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:115
const C_NOT_NULL
Helper constant for column hash functions with "NOT NULL" constraint for better readability.
Definition: Schema.qm.dox.h:117
Provides information on schema changes.
Definition: Schema.qm.dox.h:289
bool created
Set to True if only creations / additions were made.
Definition: Schema.qm.dox.h:293
*hash< string, int > change_map
Change map; action code -> count.
Definition: Schema.qm.dox.h:299
int num_changes
The total number of changes made.
Definition: Schema.qm.dox.h:296
*hash< string, int > data_change_map
Summary map for data changes; upsert action code -> count.
Definition: Schema.qm.dox.h:302
Schema option hash definitions.
Definition: Schema.qm.dox.h:364
*string data_ts
explicit data tablespace name
Definition: Schema.qm.dox.h:366
*hash< auto > db_opts
options for SqlUtil::Database::constructor()
Definition: Schema.qm.dox.h:372
*string index_ts
explicit index tablespace name
Definition: Schema.qm.dox.h:369