Consolidated ASP Classic MVC framework from best components
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

163 Zeilen
7.1KB

  1. '=======================================================================================================================
  2. ' MIGRATION GENERATOR
  3. '=======================================================================================================================
  4. ' Generates a new migration file with timestamp-based versioning.
  5. '
  6. ' Usage:
  7. ' cscript //nologo scripts\generateMigration.vbs migration_name
  8. '
  9. ' Example:
  10. ' cscript //nologo scripts\generateMigration.vbs create_users_table
  11. ' Creates: db/migrations/20260109153045_create_users_table.asp
  12. '
  13. Option Explicit
  14. Dim fso, migrationName, timestamp, filename, filepath, content
  15. Set fso = CreateObject("Scripting.FileSystemObject")
  16. ' Check arguments
  17. If WScript.Arguments.Count < 1 Then
  18. WScript.Echo "Usage: cscript //nologo scripts\generateMigration.vbs migration_name"
  19. WScript.Echo ""
  20. WScript.Echo "Example:"
  21. WScript.Echo " cscript //nologo scripts\generateMigration.vbs create_users_table"
  22. WScript.Quit 1
  23. End If
  24. migrationName = WScript.Arguments(0)
  25. ' Validate migration name (alphanumeric and underscore only)
  26. If Not IsValidMigrationName(migrationName) Then
  27. WScript.Echo "Error: Migration name must contain only letters, numbers, and underscores"
  28. WScript.Quit 1
  29. End If
  30. ' Generate timestamp (YYYYMMDDHHMMSS)
  31. timestamp = GetTimestamp()
  32. ' Create filename
  33. filename = timestamp & "_" & migrationName & ".asp"
  34. ' Ensure migrations directory exists
  35. Dim migrationsDir
  36. migrationsDir = fso.GetParentFolderName(WScript.ScriptFullName) & "\..\db\migrations"
  37. migrationsDir = fso.GetAbsolutePathName(migrationsDir)
  38. If Not fso.FolderExists(migrationsDir) Then
  39. CreateDirectoryPath migrationsDir
  40. End If
  41. filepath = migrationsDir & "\" & filename
  42. ' Check if file already exists
  43. If fso.FileExists(filepath) Then
  44. WScript.Echo "Error: Migration file already exists: " & filename
  45. WScript.Quit 1
  46. End If
  47. ' Generate migration content
  48. content = GenerateMigrationContent(migrationName)
  49. ' Write the file
  50. Dim file
  51. Set file = fso.CreateTextFile(filepath, True)
  52. file.Write content
  53. file.Close
  54. WScript.Echo "Migration created: " & filename
  55. WScript.Echo "Path: " & filepath
  56. WScript.Echo ""
  57. WScript.Echo "Edit the file to add your migration logic, then run:"
  58. WScript.Echo " cscript //nologo scripts\runMigrations.vbs"
  59. WScript.Quit 0
  60. '=======================================================================================================================
  61. ' HELPER FUNCTIONS
  62. '=======================================================================================================================
  63. Function GetTimestamp()
  64. Dim dtNow, sYear, sMonth, sDay, sHour, sMinute, sSecond
  65. dtNow = Now()
  66. sYear = Year(dtNow)
  67. sMonth = Right("0" & Month(dtNow), 2)
  68. sDay = Right("0" & Day(dtNow), 2)
  69. sHour = Right("0" & Hour(dtNow), 2)
  70. sMinute = Right("0" & Minute(dtNow), 2)
  71. sSecond = Right("0" & Second(dtNow), 2)
  72. GetTimestamp = sYear & sMonth & sDay & sHour & sMinute & sSecond
  73. End Function
  74. Function IsValidMigrationName(name)
  75. Dim regex
  76. Set regex = New RegExp
  77. regex.Pattern = "^[a-zA-Z0-9_]+$"
  78. IsValidMigrationName = regex.Test(name)
  79. End Function
  80. Function GenerateMigrationContent(name)
  81. Dim template
  82. template = "<%"& vbCrLf
  83. template = template & "'======================================================================================================================="& vbCrLf
  84. template = template & "' MIGRATION: " & name & vbCrLf
  85. template = template & "'======================================================================================================================="& vbCrLf
  86. template = template & "' This migration was auto-generated. Add your migration logic below."& vbCrLf
  87. template = template & "'"& vbCrLf
  88. template = template & "' The migration object provides these helper methods:"& vbCrLf
  89. template = template & "' - migration.ExecuteSQL(sql) - Execute raw SQL"& vbCrLf
  90. template = template & "' - migration.CreateTable(name, columns) - Create a table"& vbCrLf
  91. template = template & "' - migration.DropTable(name) - Drop a table"& vbCrLf
  92. template = template & "' - migration.AddColumn(table, column, type) - Add a column"& vbCrLf
  93. template = template & "' - migration.DropColumn(table, column) - Drop a column"& vbCrLf
  94. template = template & "' - migration.CreateIndex(name, table, columns) - Create an index"& vbCrLf
  95. template = template & "' - migration.DropIndex(name, table) - Drop an index"& vbCrLf
  96. template = template & "'"& vbCrLf
  97. template = template & "' For complex operations, use migration.DB to access the database directly:"& vbCrLf
  98. template = template & "' migration.DB.Execute ""INSERT INTO users (name) VALUES (?)"", Array(""John"")"& vbCrLf
  99. template = template & "'"& vbCrLf
  100. template = template & ""& vbCrLf
  101. template = template & "'-----------------------------------------------------------------------------------------------------------------------"& vbCrLf
  102. template = template & "' UP - Apply the migration"& vbCrLf
  103. template = template & "'-----------------------------------------------------------------------------------------------------------------------"& vbCrLf
  104. template = template & "Sub Migration_Up(migration)"& vbCrLf
  105. template = template & " ' Example: Create a table"& vbCrLf
  106. template = template & " ' migration.CreateTable ""users"", ""id AUTOINCREMENT PRIMARY KEY, name VARCHAR(255) NOT NULL, email VARCHAR(255), created_at DATETIME"""& vbCrLf
  107. template = template & " "& vbCrLf
  108. template = template & " ' Example: Add an index"& vbCrLf
  109. template = template & " ' migration.CreateIndex ""idx_users_email"", ""users"", ""email"""& vbCrLf
  110. template = template & " "& vbCrLf
  111. template = template & " ' TODO: Add your migration logic here"& vbCrLf
  112. template = template & " "& vbCrLf
  113. template = template & "End Sub"& vbCrLf
  114. template = template & ""& vbCrLf
  115. template = template & "'-----------------------------------------------------------------------------------------------------------------------"& vbCrLf
  116. template = template & "' DOWN - Rollback the migration"& vbCrLf
  117. template = template & "'-----------------------------------------------------------------------------------------------------------------------"& vbCrLf
  118. template = template & "Sub Migration_Down(migration)"& vbCrLf
  119. template = template & " ' Example: Drop the table"& vbCrLf
  120. template = template & " ' migration.DropTable ""users"""& vbCrLf
  121. template = template & " "& vbCrLf
  122. template = template & " ' TODO: Add your rollback logic here (reverse the Up migration)"& vbCrLf
  123. template = template & " "& vbCrLf
  124. template = template & "End Sub"& vbCrLf
  125. template = template & "%>"& vbCrLf
  126. GenerateMigrationContent = template
  127. End Function
  128. Sub CreateDirectoryPath(path)
  129. Dim parentPath
  130. If Not fso.FolderExists(path) Then
  131. parentPath = fso.GetParentFolderName(path)
  132. If parentPath <> "" Then
  133. CreateDirectoryPath parentPath
  134. End If
  135. fso.CreateFolder path
  136. End If
  137. End Sub

Powered by TurnKey Linux.