Export and Import of Database Schema

ExportSchema and ImportSchema are BuiltIn procedures that are available for use with source control systems.

These procedures operate on all database tables except for those under the BuiltIn module, and are designed to sync database structures and definitions between systems as well as procedures and code, but not database records. An additional system-specific script is recommended for managing the export and import of database records and attachments needed as part of a system's configuration.

 

Requirement

It is important to note that the source and destination instances used in the export and import should have the same version of Moxie.

 

File Structure

Fields and Relationships are stored as .tab files, and use TableName.tab as the filename. These files are stored under the /Fields and /Rltns folders, respectively.

Procedures are individually stored as .mox files, and grouped in folders for each table - formatted as /Procs/TableName/ProcName.mox

 

Encoding Special Characters - $CrLf, $Tab, $I

$CrLf, $Tab, and $I characters used in Fields and Relationships are encoded as [cnw-crlf], [cnw-tab], [cnw-i], respectively, so that they do not corrupt the formatting of .tab files.

These previously used angle brackets <>, but the above convention replaced that to avoid the issue with WebSafe$ and how it escapes angle brackets on Import.

 

Tables

The files under the /Fields folder are used in syncing tables, with the assumption that since all of the tables have at least one field (Alias), then all of the tables to be imported should have a counterpart in the /Fields folder

To rename a table, use "_Rename_" in the filename - e.g. "Old.Table.Name_Rename_New.Table.Name.tab"

 

Fields

To rename a field, add the following line into the DevNote column - "# NewFieldName: FieldName" - without the quotes, and replace "FieldName" with the desired name of the field

Alias Next= is not updated if source and destination are numbers, and is only reset if explicitly triggered.
To trigger a Reset on the next alias, add the following line into the Attr column - "# Next: Reset" - without the quotes

 

Procedures

Each procedure that is exported has its Source prepended with a metadata block in comments surrounded by ### Start Metadata ### and ### End Metadata ###

Each attribute of the procedure that has a set value is added in as one line within the block, formatted as "# FieldName: FieldValue" - e.g. # Type: Public Method

If any of the fields other than Source contain ### Start Metadata ### and ### End Metadata ###, the hash signs are replaced with dashes --- to prevent parsing issues on Import

To rename a procedure, one could add the following line to the metadata block - "# NewProcName: NameOfProc". However, if the proc exists as another name on the source, and doesn't have a match on destination, it would just create a new proc on the destination, and delete procs that weren't in the source

 

Logging of Import results

Results of running the import script are stored in a timestamped folder on Work/Import/Logs_{Timestamp}.

Each operation's results are stored in its own .tab file. For example, UpdateFields.tab would contain a list of all of the field names that got updated, and the tables that they are under. 

A Summary.tab file is created with a tally on how many tables, fields, relationships or procedures got created, updated, or deleted.

In the event of an error, there are logs saved of the query list under Work/Import/CatchErr_{Timestamp}.