Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

171 wiersze
5.6KB

  1. <%
  2. '=======================================================================================================================
  3. ' MIGRATION: seed_sample_cards
  4. '=======================================================================================================================
  5. Sub Migration_Up(migration)
  6. Call SeedBoardCards(migration, "website-redesign", "sample.seed")
  7. Call SeedBoardCards(migration, "q3-launch-plan", "sample.seed")
  8. End Sub
  9. Sub Migration_Down(migration)
  10. Call DbExecute(migration, "DELETE FROM [cards] WHERE [created_by] = ?", Array("sample.seed"))
  11. End Sub
  12. Private Sub SeedBoardCards(migration, boardSlug, seedUser)
  13. Dim boardId
  14. boardId = GetBoardIdBySlug(migration, boardSlug)
  15. If boardId = 0 Then Exit Sub
  16. Dim colBacklog, colInProgress, colReview, colDone
  17. Dim laneStandard, laneExpedite, laneBlocked
  18. colBacklog = GetColumnIdByName(migration, boardId, "Backlog")
  19. colInProgress = GetColumnIdByName(migration, boardId, "In Progress")
  20. colReview = GetColumnIdByName(migration, boardId, "Review")
  21. colDone = GetColumnIdByName(migration, boardId, "Done")
  22. laneStandard = GetSwimLaneIdByName(migration, boardId, "Standard")
  23. laneExpedite = GetSwimLaneIdByName(migration, boardId, "Expedite")
  24. laneBlocked = GetSwimLaneIdByName(migration, boardId, "Blocked")
  25. If colBacklog > 0 And laneStandard > 0 Then
  26. Call EnsureCard(migration, boardId, colBacklog, laneStandard, "JOB-1001", "Collect requirements", 0, seedUser)
  27. End If
  28. If colInProgress > 0 And laneExpedite > 0 Then
  29. Call EnsureCard(migration, boardId, colInProgress, laneExpedite, "JOB-1002", "Design homepage wireframe", 0, seedUser)
  30. End If
  31. If colReview > 0 And laneStandard > 0 Then
  32. Call EnsureCard(migration, boardId, colReview, laneStandard, "JOB-1003", "Stakeholder content review", 0, seedUser)
  33. End If
  34. If colDone > 0 And laneStandard > 0 Then
  35. Call EnsureCard(migration, boardId, colDone, laneStandard, "JOB-1004", "Set up board conventions", 0, seedUser)
  36. End If
  37. If colBacklog > 0 And laneBlocked > 0 Then
  38. Call EnsureCard(migration, boardId, colBacklog, laneBlocked, "JOB-1005", "Await vendor assets", 0, seedUser)
  39. End If
  40. End Sub
  41. Private Sub EnsureCard(migration, boardId, columnId, swimLaneId, jobNumber, jobName, cardPosition, seedUser)
  42. If GetCardIdByJobNumber(migration, boardId, jobNumber) = 0 Then
  43. Call DbExecute(migration, _
  44. "INSERT INTO [cards] ([board_id],[column_id],[swim_lane_id],[job_number],[job_name],[position],[created_at],[created_by],[updated_at],[updated_by]) VALUES (?,?,?,?,?,?,?,?,?,?)", _
  45. Array(boardId, columnId, swimLaneId, jobNumber, jobName, cardPosition, Now(), seedUser, Now(), seedUser))
  46. End If
  47. End Sub
  48. Private Function GetCardIdByJobNumber(migration, boardId, jobNumber)
  49. Dim rs
  50. Set rs = DbQuery(migration, "SELECT TOP 1 [id] FROM [cards] WHERE [board_id] = ? AND [job_number] = ?", Array(boardId, jobNumber))
  51. If rs.EOF Then
  52. GetCardIdByJobNumber = 0
  53. Else
  54. GetCardIdByJobNumber = CLng(rs(0))
  55. End If
  56. Call CloseRecordset(rs)
  57. End Function
  58. Private Function GetBoardIdBySlug(migration, boardSlug)
  59. Dim rs
  60. Set rs = DbQuery(migration, "SELECT TOP 1 [id] FROM [boards] WHERE [slug] = ?", Array(boardSlug))
  61. If rs.EOF Then
  62. GetBoardIdBySlug = 0
  63. Else
  64. GetBoardIdBySlug = CLng(rs(0))
  65. End If
  66. Call CloseRecordset(rs)
  67. End Function
  68. Private Function GetColumnIdByName(migration, boardId, columnName)
  69. Dim rs
  70. Set rs = DbQuery(migration, "SELECT TOP 1 [id] FROM [board_columns] WHERE [board_id] = ? AND [name] = ?", Array(boardId, columnName))
  71. If rs.EOF Then
  72. GetColumnIdByName = 0
  73. Else
  74. GetColumnIdByName = CLng(rs(0))
  75. End If
  76. Call CloseRecordset(rs)
  77. End Function
  78. Private Function GetSwimLaneIdByName(migration, boardId, laneName)
  79. Dim rs
  80. Set rs = DbQuery(migration, "SELECT TOP 1 [id] FROM [swim_lanes] WHERE [board_id] = ? AND [name] = ?", Array(boardId, laneName))
  81. If rs.EOF Then
  82. GetSwimLaneIdByName = 0
  83. Else
  84. GetSwimLaneIdByName = CLng(rs(0))
  85. End If
  86. Call CloseRecordset(rs)
  87. End Function
  88. Private Sub CloseRecordset(ByRef rs)
  89. If IsObject(rs) Then
  90. If Not rs Is Nothing Then
  91. On Error Resume Next
  92. rs.Close
  93. Set rs = Nothing
  94. On Error GoTo 0
  95. End If
  96. End If
  97. End Sub
  98. Private Sub DbExecute(migration, sql, params)
  99. On Error Resume Next
  100. migration.DB.Execute sql, params
  101. If Err.Number = 0 Then
  102. On Error GoTo 0
  103. Exit Sub
  104. End If
  105. Err.Clear
  106. On Error GoTo 0
  107. Dim conn, cmd
  108. Set conn = migration.Connection
  109. Set cmd = CreateObject("ADODB.Command")
  110. Set cmd.ActiveConnection = conn
  111. cmd.CommandText = sql
  112. If IsArray(params) Then
  113. cmd.Execute , params
  114. ElseIf IsEmpty(params) Then
  115. cmd.Execute
  116. Else
  117. cmd.Execute , Array(params)
  118. End If
  119. Set cmd = Nothing
  120. End Sub
  121. Private Function DbQuery(migration, sql, params)
  122. On Error Resume Next
  123. Set DbQuery = migration.DB.Query(sql, params)
  124. If Err.Number = 0 Then
  125. On Error GoTo 0
  126. Exit Function
  127. End If
  128. Err.Clear
  129. On Error GoTo 0
  130. Dim conn, cmd, rs
  131. Set conn = migration.Connection
  132. Set cmd = CreateObject("ADODB.Command")
  133. Set cmd.ActiveConnection = conn
  134. cmd.CommandText = sql
  135. If IsArray(params) Then
  136. Set rs = cmd.Execute(, params)
  137. ElseIf IsEmpty(params) Then
  138. Set rs = cmd.Execute()
  139. Else
  140. Set rs = cmd.Execute(, Array(params))
  141. End If
  142. Set DbQuery = rs
  143. Set cmd = Nothing
  144. End Function
  145. %>

Powered by TurnKey Linux.