-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmigration-create.ps1
More file actions
27 lines (20 loc) · 1.1 KB
/
migration-create.ps1
File metadata and controls
27 lines (20 loc) · 1.1 KB
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
param (
[string]$migrationName
)
$xmlNamespace = "http://www.liquibase.org/xml/ns/dbchangelog/1.9"
$xmlFilePath = ".\src\main\resources\db\changelog\changelog-master.xml"
$xmlMigrationBaseUrl = "db/changelog/migrations"
$templateFilePath = ".\src\main\resources\db\changelog\sample_migration.sql"
$destinationFolder = ".\src\main\resources\db\changelog\migrations"
$timestamp = [DateTimeOffset]::Now.ToUnixTimeSeconds()
$newFileName = "${timestamp}_${migrationName}.sql"
$newFilePath = Join-Path -Path $destinationFolder -ChildPath $newFileName
Write-Output "Creating migration with name ${newFileName}..."
Copy-Item -Path $templateFilePath -Destination $newFilePath
(Get-Content -Path $newFilePath) -replace 'create_sample_table', "${timestamp}_${migrationName}" | Set-Content -Path $newFilePath
$xml = [xml](get-content $xmlFilePath)
$newMigration = $xml.CreateElement("include", $xmlNamespace)
$newMigration.SetAttribute("file","$xmlMigrationBaseUrl/$newFileName")
$xml.databaseChangeLog.AppendChild($newMigration) | out-null
$xml.save($xmlFilePath)
Write-Output "Migration with name ${newFileName} created."