Class TDBVersioning

Unit

Declaration

type TDBVersioning = class(TObject)

Description

This is the class for managing database schema upgrades

Hierarchy

Overview

Methods

Public constructor Create(AConnection: TSQLConnection; ATransaction: TSQLTransaction; ASQLDir: String = '');
Public constructor Create(AConnection: TSQLConnection; ATransaction: TSQLTransaction; const ASQLScripts: array of String);
Public constructor CreateFromResources(AConnection: TSQLConnection; ATransaction: TSQLTransaction; AResourcePrefix: String = 'SQL_SCRIPT_');
Public destructor Destroy; override;
Public procedure UpgradeTo(AVer: Integer);
Public procedure UpgradeToLatest;
Public function UpgradeNeeded: Boolean;
Public function IsInitialized: Boolean;

Properties

Public property CurrentVersion: Integer read GetCurrentDBVersion;
Public property LatestVersion: Integer read GetLatestVersion;

Description

Methods

Public constructor Create(AConnection: TSQLConnection; ATransaction: TSQLTransaction; ASQLDir: String = '');
 
Parameters
ASQLDir
Directory where *.sql files will be searched. If empty string passed ProgramDir/db-updates/ will be used.
Public constructor Create(AConnection: TSQLConnection; ATransaction: TSQLTransaction; const ASQLScripts: array of String);
 
Parameters
ASQLScripts
Array of SQL commands. Each item may contains more than one command separated with semicolon (;). Multiline strings allowed. Array indexes linked with versions (first item — version 1, second item — version 2, etc...).
Public constructor CreateFromResources(AConnection: TSQLConnection; ATransaction: TSQLTransaction; AResourcePrefix: String = 'SQL_SCRIPT_');

SQL scripts stored as RCDATA resources named SQL_SCRIPT_1, SQL_SCRIPT_2, SQL_SCRIPT_3, etc... Prefix may be changes with AResourcePrefix param.

Parameters
AResourcePrefix
Prefix for resource names
Public destructor Destroy; override;
 
Public procedure UpgradeTo(AVer: Integer);

Upgrade database to specified version. If upgrade fails it rollback all changes to previous state.

Parameters
AVer
New version to upgrade (> 1)
Exceptions raised
EDBVersioningException
If SQL commands for specified version (or any intermediate) not found
ESQLDatabaseError
If error occured on executing SQL statements
Public procedure UpgradeToLatest;

Upgrade database to latest possible version

See also
UpgradeTo
Public function UpgradeNeeded: Boolean;

Checks if database can be upgraded to new version (has any not applied upgrades).

Public function IsInitialized: Boolean;

Checks if database not empty and has any upgrades applied. For the first run should return False.

Properties

Public property CurrentVersion: Integer read GetCurrentDBVersion;

Returns the version of the database it is in

Public property LatestVersion: Integer read GetLatestVersion;

Returns last available for upgrade version


Generated by PasDoc 0.16.0. Generated on 2024-11-26 16:46:03.