mirror of
https://github.com/ClusterCockpit/cc-backend
synced 2025-07-23 12:51:40 +02:00
@@ -16,7 +16,7 @@ import (
|
||||
"github.com/golang-migrate/migrate/v4/source/iofs"
|
||||
)
|
||||
|
||||
const Version uint = 4
|
||||
const Version uint = 5
|
||||
|
||||
//go:embed migrations/*
|
||||
var migrationFiles embed.FS
|
||||
|
@@ -0,0 +1,2 @@
|
||||
ALTER TABLE tag DROP COLUMN insert_time;
|
||||
ALTER TABLE jobtag DROP COLUMN insert_time;
|
@@ -0,0 +1,2 @@
|
||||
ALTER TABLE tag ADD COLUMN insert_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP;
|
||||
ALTER TABLE jobtag ADD COLUMN insert_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP;
|
@@ -0,0 +1,2 @@
|
||||
ALTER TABLE tag DROP COLUMN insert_time;
|
||||
ALTER TABLE jobtag DROP COLUMN insert_time;
|
18
internal/repository/migrations/sqlite3/05_extend-tags.up.sql
Normal file
18
internal/repository/migrations/sqlite3/05_extend-tags.up.sql
Normal file
@@ -0,0 +1,18 @@
|
||||
ALTER TABLE tag ADD COLUMN insert_ts TEXT DEFAULT NULL /* replace me */;
|
||||
ALTER TABLE jobtag ADD COLUMN insert_ts TEXT DEFAULT NULL /* replace me */;
|
||||
UPDATE tag SET insert_ts = CURRENT_TIMESTAMP;
|
||||
UPDATE jobtag SET insert_ts = CURRENT_TIMESTAMP;
|
||||
PRAGMA writable_schema = on;
|
||||
|
||||
UPDATE sqlite_master
|
||||
SET sql = replace(sql, 'DEFAULT NULL /* replace me */',
|
||||
'DEFAULT CURRENT_TIMESTAMP')
|
||||
WHERE type = 'table'
|
||||
AND name = 'tag';
|
||||
UPDATE sqlite_master
|
||||
SET sql = replace(sql, 'DEFAULT NULL /* replace me */',
|
||||
'DEFAULT CURRENT_TIMESTAMP')
|
||||
WHERE type = 'table'
|
||||
AND name = 'jobtag';
|
||||
|
||||
PRAGMA writable_schema = off;
|
@@ -70,14 +70,14 @@ func (r *JobRepository) CreateTag(tagType string, tagName string) (tagId int64,
|
||||
|
||||
func (r *JobRepository) CountTags(user *auth.User) (tags []schema.Tag, counts map[string]int, err error) {
|
||||
tags = make([]schema.Tag, 0, 100)
|
||||
xrows, err := r.DB.Queryx("SELECT * FROM tag")
|
||||
xrows, err := r.DB.Queryx("SELECT id, tag_type, tag_name FROM tag")
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
for xrows.Next() {
|
||||
var t schema.Tag
|
||||
if err := xrows.StructScan(&t); err != nil {
|
||||
if err = xrows.StructScan(&t); err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
tags = append(tags, t)
|
||||
@@ -89,7 +89,7 @@ func (r *JobRepository) CountTags(user *auth.User) (tags []schema.Tag, counts ma
|
||||
GroupBy("t.tag_name")
|
||||
|
||||
if user != nil && user.HasAnyRole([]auth.Role{auth.RoleAdmin, auth.RoleSupport}) { // ADMIN || SUPPORT: Count all jobs
|
||||
log.Info("CountTags: User Admin or Support -> Count all Jobs for Tags")
|
||||
log.Debug("CountTags: User Admin or Support -> Count all Jobs for Tags")
|
||||
// Unchanged: Needs to be own case still, due to UserRole/NoRole compatibility handling in else case
|
||||
} else if user != nil && user.HasRole(auth.RoleManager) { // MANAGER: Count own jobs plus project's jobs
|
||||
// Build ("project1", "project2", ...) list of variable length directly in SQL string
|
||||
@@ -107,7 +107,7 @@ func (r *JobRepository) CountTags(user *auth.User) (tags []schema.Tag, counts ma
|
||||
for rows.Next() {
|
||||
var tagName string
|
||||
var count int
|
||||
if err := rows.Scan(&tagName, &count); err != nil {
|
||||
if err = rows.Scan(&tagName, &count); err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
counts[tagName] = count
|
||||
|
Reference in New Issue
Block a user