From 4fbda900ea182bc4be9a1bb9dd3e96eaa4ba0fc2 Mon Sep 17 00:00:00 2001 From: joyfullservice Date: Fri, 21 Jul 2023 16:10:45 -0500 Subject: [PATCH] Integrate schema export with existing export flow Schema export is now running as a part of the export process. #415 --- .../modules/modConstants.bas | 1 + .../modules/modImportExport.bas | 65 +++++++++++++++++++ 2 files changed, 66 insertions(+) diff --git a/Version Control.accda.src/modules/modConstants.bas b/Version Control.accda.src/modules/modConstants.bas index 8c8f975c..c382e109 100644 --- a/Version Control.accda.src/modules/modConstants.bas +++ b/Version Control.accda.src/modules/modConstants.bas @@ -83,6 +83,7 @@ End Enum ' Database server types for external databases Public Enum eDatabaseServerType + estUnknown estMsSql estMySql End Enum diff --git a/Version Control.accda.src/modules/modImportExport.bas b/Version Control.accda.src/modules/modImportExport.bas index 4c9c7265..66216804 100644 --- a/Version Control.accda.src/modules/modImportExport.bas +++ b/Version Control.accda.src/modules/modImportExport.bas @@ -90,6 +90,9 @@ Public Sub ExportSource(blnFullExport As Boolean, Optional intFilter As eContain Perf.OperationEnd End If + ' Export any external database schemas + ExportSchemas blnFullExport + ' Finish header section Log.Spacer Log.Add "Scanning " & IIf(blnFullExport, "source files...", "for changes...") @@ -577,6 +580,68 @@ CleanUp: End Sub +'--------------------------------------------------------------------------------------- +' Procedure : ExportSchemas +' Author : Adam Waller +' Date : 7/21/2023 +' Purpose : Export any external database schemas configured in options +'--------------------------------------------------------------------------------------- +' +Public Sub ExportSchemas(blnFullExport As Boolean) + + Dim varKey As Variant + Dim strName As String + Dim strType As String + Dim cSchema As IDbSchema + Dim dParams As Dictionary + Dim strFile As String + + ' Skip this section if there are no connections defined. + If Options.SchemaExports.Count = 0 Then Exit Sub + + ' Loop through schemas + Log.Spacer + Log.Add "Scanning external databases..." + Perf.OperationStart "Scan External Databases" + For Each varKey In Options.SchemaExports.Keys + Select Case Options.SchemaExports(varKey)("DatabaseType") + Case eDatabaseServerType.estMsSql + strType = " (MSSQL)" + Set cSchema = New clsSchemaMsSql + Case eDatabaseServerType.estMySql + strType = " (MySQL)" + 'Set cSchema = New clsSchemaMySql + End Select + strName = varKey + Log.Add " - " & strName & strType + Perf.CategoryStart strName & strType + Log.Flush + ' Load parameters for initializing the connection + Set dParams = CloneDictionary(Options.SchemaExports(varKey)) + dParams("Name") = strName + + strFile = BuildPath2(Options.GetExportFolder & "databases", GetSafeFileName(strName), ".env") + If Not FSO.FileExists(strFile) Then + Log.Add " No connection string found. (.env)", , , "Red", , True + Log.Error eelWarning, "File not found: " & strFile, ModuleName & ".ExportSchemas" + Log.Add "Set the connection string for this external database connection in VCS options to automatically create this file.", False + Log.Add "(This file may contain authentication credentials and should be excluded from version control.)", False + Else + ' Use .env file to initialize connection + With New clsDotEnv + .LoadFromFile strFile + .MergeIntoDictionary dParams, False + End With + cSchema.Initialize dParams + cSchema.Export blnFullExport + End If + Perf.CategoryEnd + Next varKey + Perf.OperationEnd + +End Sub + + '--------------------------------------------------------------------------------------- ' Procedure : Build (Full build or Merge Build) ' Author : Adam Waller