grim/youtrack-import

c3d30cb6d4ea
Parents d8a71dd2be73
Children
Grab the distinct version and milestone fields from tickets as well
--- a/trac/versions.go Tue Sep 01 21:09:25 2020 -0500
+++ b/trac/versions.go Mon Sep 07 22:50:24 2020 -0500
@@ -8,29 +8,40 @@
type version struct {
Name string `db:"name"`
- Time int64 `db:"time"`
+ Time sql.NullInt64 `db:"time"`
Description sql.NullString `db:"description"`
}
func (e *environment) loadVersions() ([]youtrack.Version, error) {
versions := []version{}
- // we grab both the versions and the milestones as milestones are
- // essentially treated as the fix version in trac.
+ // we grab the values from the version and the milestone tables as well as
+ // the distinct values for version and milestone from each ticket to figure
+ // out what version are all here. In the Pidgin trac, milestones were
+ // essentially the fix version so it makes sense.
err := e.db.Select(
&versions,
- `SELECT
- a.name, a.time, a.description
- FROM
- trac_pidgin.version a
- UNION ALL
- SELECT
- b.name, b.due as time, b.description
- FROM
- trac_pidgin.milestone b
- WHERE NOT EXISTS
- (SELECT NULL FROM trac_pidgin.version c WHERE c.name = b.name)
- ORDER BY
- name`,
+ `
+SELECT y.name, coalesce(y.time,0) AS time, y.description
+FROM (
+ SELECT x.name, x.time, x.description, row_number() OVER (PARTITION BY x.name ORDER BY rank) as rnum
+ FROM (
+ SELECT a.name, a.time, a.description, 1 AS rank
+ FROM trac_pidgin.version a
+ UNION ALL
+ SELECT b.name, b.due as time, b.description, 2
+ FROM trac_pidgin.milestone b
+ UNION ALL
+ SELECT t1.version, NULL, NULL, 3
+ FROM trac_pidgin.ticket t1
+ WHERE t1.version IS NOT NULL AND t1.version != ''
+ UNION ALL
+ SELECT t1.milestone, NULL, NULL, 4
+ FROM trac_pidgin.ticket t1
+ WHERE t1.milestone IS NOT NULL AND t1.milestone != ''
+ ) AS x
+) AS y
+WHERE y.rnum = 1;
+`,
)
ytVersions := make([]youtrack.Version, len(versions))
@@ -47,9 +58,9 @@
Description: convertString(v.Description),
}
- if v.Time != 0 {
+ if v.Time.Valid {
ytVersion.Released = true
- ytVersion.ReleaseDate = convertTime(v.Time)
+ ytVersion.ReleaseDate = convertTime(v.Time.Int64)
}
return ytVersion