|
- <%
- '=======================================================================================================================
- ' MIGRATION: seed_sample_cards
- '=======================================================================================================================
-
- Sub Migration_Up(migration)
- Call SeedBoardCards(migration, "website-redesign", "sample.seed")
- Call SeedBoardCards(migration, "q3-launch-plan", "sample.seed")
- End Sub
-
- Sub Migration_Down(migration)
- Call DbExecute(migration, "DELETE FROM [cards] WHERE [created_by] = ?", Array("sample.seed"))
- End Sub
-
- Private Sub SeedBoardCards(migration, boardSlug, seedUser)
- Dim boardId
- boardId = GetBoardIdBySlug(migration, boardSlug)
- If boardId = 0 Then Exit Sub
-
- Dim colBacklog, colInProgress, colReview, colDone
- Dim laneStandard, laneExpedite, laneBlocked
-
- colBacklog = GetColumnIdByName(migration, boardId, "Backlog")
- colInProgress = GetColumnIdByName(migration, boardId, "In Progress")
- colReview = GetColumnIdByName(migration, boardId, "Review")
- colDone = GetColumnIdByName(migration, boardId, "Done")
-
- laneStandard = GetSwimLaneIdByName(migration, boardId, "Standard")
- laneExpedite = GetSwimLaneIdByName(migration, boardId, "Expedite")
- laneBlocked = GetSwimLaneIdByName(migration, boardId, "Blocked")
-
- If colBacklog > 0 And laneStandard > 0 Then
- Call EnsureCard(migration, boardId, colBacklog, laneStandard, "JOB-1001", "Collect requirements", 0, seedUser)
- End If
-
- If colInProgress > 0 And laneExpedite > 0 Then
- Call EnsureCard(migration, boardId, colInProgress, laneExpedite, "JOB-1002", "Design homepage wireframe", 0, seedUser)
- End If
-
- If colReview > 0 And laneStandard > 0 Then
- Call EnsureCard(migration, boardId, colReview, laneStandard, "JOB-1003", "Stakeholder content review", 0, seedUser)
- End If
-
- If colDone > 0 And laneStandard > 0 Then
- Call EnsureCard(migration, boardId, colDone, laneStandard, "JOB-1004", "Set up board conventions", 0, seedUser)
- End If
-
- If colBacklog > 0 And laneBlocked > 0 Then
- Call EnsureCard(migration, boardId, colBacklog, laneBlocked, "JOB-1005", "Await vendor assets", 0, seedUser)
- End If
- End Sub
-
- Private Sub EnsureCard(migration, boardId, columnId, swimLaneId, jobNumber, jobName, cardPosition, seedUser)
- If GetCardIdByJobNumber(migration, boardId, jobNumber) = 0 Then
- Call DbExecute(migration, _
- "INSERT INTO [cards] ([board_id],[column_id],[swim_lane_id],[job_number],[job_name],[position],[created_at],[created_by],[updated_at],[updated_by]) VALUES (?,?,?,?,?,?,?,?,?,?)", _
- Array(boardId, columnId, swimLaneId, jobNumber, jobName, cardPosition, Now(), seedUser, Now(), seedUser))
- End If
- End Sub
-
- Private Function GetCardIdByJobNumber(migration, boardId, jobNumber)
- Dim rs
- Set rs = DbQuery(migration, "SELECT TOP 1 [id] FROM [cards] WHERE [board_id] = ? AND [job_number] = ?", Array(boardId, jobNumber))
- If rs.EOF Then
- GetCardIdByJobNumber = 0
- Else
- GetCardIdByJobNumber = CLng(rs(0))
- End If
- Call CloseRecordset(rs)
- End Function
-
- Private Function GetBoardIdBySlug(migration, boardSlug)
- Dim rs
- Set rs = DbQuery(migration, "SELECT TOP 1 [id] FROM [boards] WHERE [slug] = ?", Array(boardSlug))
- If rs.EOF Then
- GetBoardIdBySlug = 0
- Else
- GetBoardIdBySlug = CLng(rs(0))
- End If
- Call CloseRecordset(rs)
- End Function
-
- Private Function GetColumnIdByName(migration, boardId, columnName)
- Dim rs
- Set rs = DbQuery(migration, "SELECT TOP 1 [id] FROM [board_columns] WHERE [board_id] = ? AND [name] = ?", Array(boardId, columnName))
- If rs.EOF Then
- GetColumnIdByName = 0
- Else
- GetColumnIdByName = CLng(rs(0))
- End If
- Call CloseRecordset(rs)
- End Function
-
- Private Function GetSwimLaneIdByName(migration, boardId, laneName)
- Dim rs
- Set rs = DbQuery(migration, "SELECT TOP 1 [id] FROM [swim_lanes] WHERE [board_id] = ? AND [name] = ?", Array(boardId, laneName))
- If rs.EOF Then
- GetSwimLaneIdByName = 0
- Else
- GetSwimLaneIdByName = CLng(rs(0))
- End If
- Call CloseRecordset(rs)
- End Function
-
- Private Sub CloseRecordset(ByRef rs)
- If IsObject(rs) Then
- If Not rs Is Nothing Then
- On Error Resume Next
- rs.Close
- Set rs = Nothing
- On Error GoTo 0
- End If
- End If
- End Sub
-
- Private Sub DbExecute(migration, sql, params)
- On Error Resume Next
- migration.DB.Execute sql, params
- If Err.Number = 0 Then
- On Error GoTo 0
- Exit Sub
- End If
- Err.Clear
- On Error GoTo 0
-
- Dim conn, cmd
- Set conn = migration.Connection
- Set cmd = CreateObject("ADODB.Command")
- Set cmd.ActiveConnection = conn
- cmd.CommandText = sql
-
- If IsArray(params) Then
- cmd.Execute , params
- ElseIf IsEmpty(params) Then
- cmd.Execute
- Else
- cmd.Execute , Array(params)
- End If
-
- Set cmd = Nothing
- End Sub
-
- Private Function DbQuery(migration, sql, params)
- On Error Resume Next
- Set DbQuery = migration.DB.Query(sql, params)
- If Err.Number = 0 Then
- On Error GoTo 0
- Exit Function
- End If
- Err.Clear
- On Error GoTo 0
-
- Dim conn, cmd, rs
- Set conn = migration.Connection
- Set cmd = CreateObject("ADODB.Command")
- Set cmd.ActiveConnection = conn
- cmd.CommandText = sql
-
- If IsArray(params) Then
- Set rs = cmd.Execute(, params)
- ElseIf IsEmpty(params) Then
- Set rs = cmd.Execute()
- Else
- Set rs = cmd.Execute(, Array(params))
- End If
-
- Set DbQuery = rs
- Set cmd = Nothing
- End Function
- %>
|