Commit 910dc15c authored by Andreas Mieke's avatar Andreas Mieke

Fix Crash-Version-Association

parent 04785b04
# Changelog
## Version 1.1.1
* Add: `govendor sync` step to update guide
* Change: Updated GROM to current master
* Fix: Crash-Version-Association
* Fix: Correctly install stylesheet
## Version 1.1.0
* Add: Version dropdown next to product dropdown
......
......@@ -33,6 +33,12 @@ Then the submodule and breakpads submodules need to be updated:
git submodule update --init --recursive
```
Now check with govendor for updated dependencies, run:
```
govendor sync
```
After that you have to run the database migrations. This can be done by running
```
......
......@@ -40,6 +40,8 @@ type Version struct {
ProductID uuid.UUID `sql:"type:uuid NOT NULL DEFAULT NULL"`
Product Product
Crashes []*Crash `gorm:"many2many:crash_versions;"`
}
// Versions contains all currently available versions and is used for the switcher in the header
......@@ -96,8 +98,7 @@ type Crash struct {
ProductID uuid.UUID `sql:"type:uuid NOT NULL DEFAULT NULL"`
Product Product
VersionID uuid.UUID `sql:"type:uuid NOT NULL DEFAULT NULL"`
Version Version
Versions []*Version `gorm:"many2many:crash_versions;"`
Fixed bool `sql:"DEFAULT false"`
}
......@@ -267,6 +268,8 @@ func InitDb(connection string) error {
Db.Model(&Report{}).AddForeignKey("version_id", "versions(id)", "RESTRICT", "RESTRICT")
Db.Model(&Symfile{}).AddForeignKey("product_id", "products(id)", "RESTRICT", "RESTRICT")
Db.Model(&Symfile{}).AddForeignKey("version_id", "versions(id)", "RESTRICT", "RESTRICT")
Db.Table("crash_versions").AddForeignKey("crash_id", "crashes(id)", "RESTRICT", "RESTRICT")
Db.Table("crash_versions").AddForeignKey("version_id", "versions(id)", "RESTRICT", "RESTRICT")
Db.Model(&Product{}).AddUniqueIndex("idx_product_slug", "slug")
Db.Model(&Version{}).AddUniqueIndex("idx_version_slug_product", "slug", "product_id")
......
BEGIN TRANSACTION;
-- Create table for many2many relationship
CREATE TABLE IF NOT EXISTS "crash_versions" (
"crash_id" uuid REFERENCES crashes(id) ON DELETE RESTRICT,
"version_id" uuid REFERENCES versions(id) ON DELETE RESTRICT,
PRIMARY KEY ("crash_id","version_id")
);
-- Populate table with existing crash/version relationships based on reports
INSERT INTO crash_versions SELECT crash_id, version_id FROM reports GROUP BY crash_id, version_id;
-- Drop no longer needed version_id from crashes
ALTER TABLE crashes DROP COLUMN IF EXISTS version_id;
END TRANSACTION;
......@@ -171,6 +171,7 @@ func processReport(Report database.Report, reprocess bool) {
tx.Create(&Report)
}
tx.Save(&Crash)
tx.Commit()
}
......@@ -194,7 +195,6 @@ func processCrash(tx *gorm.DB, Report database.Report, reprocess bool, Crash *da
Crash.LinCrashCount = 0
Crash.ProductID = Report.ProductID
Crash.VersionID = Report.VersionID
Crash.Fixed = false
......@@ -213,16 +213,14 @@ func processCrash(tx *gorm.DB, Report database.Report, reprocess bool, Crash *da
}
tx.Save(&Crash)
}
var id uuid.UUID
rows, err := database.Db.Model(&database.Report{}).Where("crash_id = ?", Crash.ID).Select("version_id AS vid").Group("version_id").Rows()
if err == nil {
defer rows.Close()
for rows.Next() {
rows.Scan(&id)
if id == Report.VersionID {
break
}
tx.Model(&Crash).Set("fixed", false)
tx.Model(&Crash).Related(&Crash.Versions, "Versions")
for _, Version := range Crash.Versions {
if Version.ID == Report.Version.ID {
break
}
Crash.Fixed = false
}
tx.Model(&Crash).Association("Versions").Append(&Report.Version)
}
......@@ -59,7 +59,8 @@ func GetCrashes(c *gin.Context) {
}
all, ver := GetVersionCookie(c)
if !all {
query = query.Where("version_id = ?", ver.ID)
query = query.Where("id in (?)", database.Db.Table("crash_versions").Select("crash_id").Where("version_id = ?", ver.ID).QueryExpr())
//query = query.Model(&ver).Association("Versions")
}
offset, err := strconv.Atoi(c.DefaultQuery("offset", "0"))
if err != nil {
......@@ -67,7 +68,7 @@ func GetCrashes(c *gin.Context) {
}
var count int
query.Model(database.Crash{}).Count(&count)
query.Where("fixed = false").Order("all_crash_count DESC").Offset(offset).Limit(50).Preload("Product").Preload("Version").Find(&Crashes)
query.Where("fixed = false").Order("all_crash_count DESC").Offset(offset).Limit(50).Find(&Crashes)
var next int
var prev int
if (offset + 50) >= count {
......
......@@ -35,6 +35,7 @@ func PostReports(c *gin.Context) {
return
}
Report.ProductID = Product.ID
Report.Product = Product
var Version database.Version
if err = database.Db.First(&Version, "slug = ? AND product_id = ? AND ignore = false", c.Request.FormValue("ver"), Report.ProductID).Error; err != nil {
......@@ -42,6 +43,7 @@ func PostReports(c *gin.Context) {
return
}
Report.VersionID = Version.ID
Report.Version = Version
Report.ProcessUptime, _ = strconv.Atoi(c.Request.FormValue("ptime"))
Report.EMail = c.Request.FormValue("email")
......
......@@ -39,10 +39,10 @@
"revisionTime": "2017-09-22T08:27:39Z"
},
{
"checksumSHA1": "uvWzKxIhqD5JzlQ7pxYlbV4kBbY=",
"checksumSHA1": "nlEiwqdbwY1eclAGG1xcC+XPV9M=",
"path": "github.com/jinzhu/gorm",
"revision": "eae7f6be603af3190e032fe3c4d465ddaf6ea3d4",
"revisionTime": "2017-06-14T08:49:39Z"
"revision": "82eb9f8a5bbb5e6b929d2f0ae5b934e6a253f94e",
"revisionTime": "2018-05-12T06:29:00Z"
},
{
"checksumSHA1": "VIp1lZm6joWhlNdwhady8u//qRw=",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment