-
Notifications
You must be signed in to change notification settings - Fork 0
/
uGerenciadorMigracaoBD.pas
75 lines (63 loc) · 1.8 KB
/
uGerenciadorMigracaoBD.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
unit uGerenciadorMigracaoBD;
interface
uses
System.Generics.Collections,
SysUtils,
uBaseMigracaoBD,
Vcl.Dialogs,
FireDAC.Stan.Intf,
FireDAC.Stan.Option,
FireDAC.Stan.Param,
FireDAC.Stan.Error,
FireDAC.DatS,
FireDAC.Phys.Intf,
FireDAC.DApt.Intf,
FireDAC.Stan.Async,
FireDAC.DApt,
FireDAC.Stan.Def,
FireDAC.Comp.DataSet,
FireDAC.Comp.Client,
FireDAC.Phys.PG;
type
TGerenciadorBDMigracao = class
private
fDacConnection: TFDConnection;
fMigracoesBDLista: TObjectList<TBaseMigracaoBD>;
public
procedure Inicializar;
procedure RegistrarMigracaoBD(MigracaoBD: TBaseMigracaoBD);
constructor Create(const Host, Database, Esquema: String);
end;
implementation
constructor TGerenciadorBDMigracao.Create(const Host, Database, Esquema: String);
begin
fDacConnection := TFDConnection.Create(nil);
fDacConnection.DriverName := 'PG';
fDacConnection.Params.Database := Database;
fDacConnection.Params.UserName := 'ALTERDATA_ADMIN';
fDacConnection.Params.Password := 'alterdata123!';
fDacConnection.Params.AddPair('Server', Host);
fDacConnection.Params.AddPair('Port', '5432');
fDacConnection.Params.AddPair('SearchPath', Esquema);
fDacConnection.Connected := True;
fDacConnection.ExecSQL(Format('SET search_path TO %s;', [Esquema]));
fMigracoesBDLista := TObjectList<TBaseMigracaoBD>.Create;
end;
procedure TGerenciadorBDMigracao.RegistrarMigracaoBD(MigracaoBD: TBaseMigracaoBD);
begin
fMigracoesBDLista.Add(MigracaoBD);
end;
procedure TGerenciadorBDMigracao.Inicializar;
var
MigracaoBD : TBaseMigracaoBD;
begin
for MigracaoBD in fMigracoesBDLista do
begin
MigracaoBD.DacConnection := fDacConnection;
if MigracaoBD.VerificarNecessidade
then MigracaoBD.Instalar;
end;
fDacConnection.Free;
fMigracoesBDLista.Free;
end;
end.