summaryrefslogtreecommitdiffstats
path: root/models/migrations/v1_17/v220.go
blob: d4007163ab0efb7b45cba9e45a2f7b33112bd1a6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// Copyright 2022 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT

package v1_17 //nolint

import (
	packages_model "code.gitea.io/gitea/models/packages"
	container_module "code.gitea.io/gitea/modules/packages/container"

	"xorm.io/xorm"
	"xorm.io/xorm/schemas"
)

func AddContainerRepositoryProperty(x *xorm.Engine) (err error) {
	if x.Dialect().URI().DBType == schemas.SQLITE {
		_, err = x.Exec("INSERT INTO package_property (ref_type, ref_id, name, value) SELECT ?, p.id, ?, u.lower_name || '/' || p.lower_name FROM package p JOIN `user` u ON p.owner_id = u.id WHERE p.type = ?",
			packages_model.PropertyTypePackage, container_module.PropertyRepository, packages_model.TypeContainer)
	} else {
		_, err = x.Exec("INSERT INTO package_property (ref_type, ref_id, name, value) SELECT ?, p.id, ?, CONCAT(u.lower_name, '/', p.lower_name) FROM package p JOIN `user` u ON p.owner_id = u.id WHERE p.type = ?",
			packages_model.PropertyTypePackage, container_module.PropertyRepository, packages_model.TypeContainer)
	}
	return err
}