msaccess-vcs-addin
msaccess-vcs-addin copied to clipboard
Export Path in a multi-developer source code environment
Background: We have 3 developers and about 50 individual ms-access databases supporting over 200 users across multiple facilities. Our distributed version control system, therefore has 4 source folders, one for each developer and a "master" repository for a common synchronization destination. Each source folder has a sub folder for each of the 50 databases. Each developer uses msaccess-vcs-addin [version control.accda] to export to our respective user# source code repositories. Then we use TortoiseHG with GIT to commit, merge, push/pull, etc. between Master and User# source. Each user synchronizes their individual source folder with \ShareDatabase\MasterRepository.
(These share and folder names below have been changed to a generic representation of the folder structure for the purpose of this discussion.) ...\ShareDatabase (database location for current version of all dbs)
...\ShareDatabase\User1-Development (User1 in progress databases, ) ...\ShareDatabase\User2-Development (User2 in progress databases) ...\ShareDatabase\User3-Development (User3 in progress databases)
...\ShareDatabase\User1-Development\Source_User1 (User1 source code repository) ...\ShareDatabase\User2-Development\Source_User2 (User2 source code repository) ...\ShareDatabase\User3-Development\Source_User3 (User3 source code repository) ...\ShareDatabase\MasterRepository (Master source code repository for all users to synch with)
PROBLEM: With version 3, as well with version 4, VCS options allows you to designate an Export Folder. When an initial export is performed by User1 [version control.accda] creates a .json file which stores the export folder location. That is great, unless you have a developer team, with each developer having a different source code folder. When the next developer (User2) has to work on the same database, [version control.accda] reads the .json file to get the export folder last used, and sets the export location to the .json export folder location. This results in User2 exporting to the User1 source code folder. Now user2 will not see the changes pending to commit in Tortoise. And similarly, User1 will see pending changes that they did not create.
We resolved this issue by a few small modifications to [version control.accda]:
- Use a couple of variables in the Options Export Folder string in Options form: "...\ShareDatabase%Uname%-Development\SOURCE_%Uname%\%dbname%.src" Results in Proj-properties.json having the following: "VCS Source Path": "...\ShareDatabase\100\%Uname%-Development\SOURCE_%Uname%\%dbname%.src"
Now version control can read the string from the .json and substitute the variables as follows:
Module modFunctions; 'Added: Gets user NT Username used in Public Function GetExportFolder Public Function User_FX() As String
Dim lSize As Long Dim lpstrBuffer As String, trimStr As String lSize = 255 lpstrBuffer = Space$(lSize) If GetUserName(lpstrBuffer, lSize) Then User_FX = Left$(lpstrBuffer, lSize - 1) Else User_FX = "Unknown" End If On Error GoTo 0 End Function
Module clsOptions; Public Function GetExportFolder() As String
Dim strFullPath As String
If Me.ExportFolder = vbNullString Then
If DatabaseFileOpen Then
' Build default path using project file name
strFullPath = CurrentProject.FullName & ".src" & PathSep
Else
' Check options file path
If Len(m_strOptionsFilePath) Then
strFullPath = FSO.GetParentFolderName(m_strOptionsFilePath)
End If
End If
Else
If Left$(Me.ExportFolder, 2) = PathSep & PathSep Then
' UNC path
strFullPath = Me.ExportFolder
ElseIf Left$(Me.ExportFolder, 1) = PathSep Then
' Relative path (from database file location)
strFullPath = CurrentProject.Path & Me.ExportFolder
Else
' Other absolute path (i.e. c:\myfiles\)
strFullPath = Me.ExportFolder
End If
' Placeholder replacements
If InStr(1, strFullPath, "%dbName%", vbTextCompare) > 0 Then
strFullPath = Replace(strFullPath, "%dbName%", CurrentProject.Name, , , vbTextCompare)
End If
' 08/01/2024 Modified by RSonnier to allow %UName% variable in the Export Folder Path
If InStr(1, strFullPath, "%Uname%", vbTextCompare) > 0 Then
strFullPath = Replace(strFullPath, "%Uname%", User_FX(), , , vbTextCompare)
End If
End If