mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
* Add Drone configuration
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
* Add more steps
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
* Add more steps
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
* Build front-end before testing it
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
* Upgrade grafana/build-container
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
* Add packaging step
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
* Trigger on push
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
* Remove some steps
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
* Enable steps
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
* Install Dockerize
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
* Use node image for test-frontend
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
* Increase number of test workers
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
* Make plugin installation depend on frontend tests
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
* Make integration tests depend on frontend tests
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
* Use grafana/build-container also for front-end tests
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
* Upgrade dependencies in order to fix front-end tests
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
* Depend on es-check
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
* Dont' depend on tests before building front-end
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
* Add more steps
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
* Fix packaging
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
* Simplify
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
* Try to build images
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
* Fix e2e tests
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
* Remove steps
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
* Install netcat
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
* Include golangci-lint with grafana/build-container
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
* Build storybook and docs website
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
* Fix e2e tests
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
* Use build image with root user
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
* Drop CircleCI dependencies
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
* Fix e2e tests
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
* Fix e2e under Drone
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
* Execute e2e server separately
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
* Use own plugin for building Docker images
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
* Use Starlark to configure Drone
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
* Add enterprise steps to pipeline
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
* Add more enterprise steps to pipeline
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
* Maintain Yarn cache
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
* Build enterprise Docker images
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
* Build Ubuntu Docker images
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
* Refactor
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
* Add Postgres integration test
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
* Add MySQL integration test
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
* Fix integration tests
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
* Parameterize integration test DB connections
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
* Categorize integration tests
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
* Use grabpl integration-tests
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
* Remove unintended change
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
* Drone: Disable Ubuntu Docker images for PR pipeline
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
* Regenerate yarn.lock
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
* Upgrade grabpl
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
* Restore Yarn cache before installing in grafana-enterprise
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
* Use separate pipelines for OSS and enterprise
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
* Let OSS builds depend on tests
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
* Restore Go cache before building back-end
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
* Reduce number of variants built for PRs
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
* Fix building of Docker images
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
* Drone: Simplify logic
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
* Drone: Use Starlark
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
* Drone: Fix syntax error
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
* Convert .drone.star to YAML
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
* Upgrade AWS Go SDK
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
* Drone: Fix Go linting
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
* Undo irrelevant changes
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
* Revert "Undo irrelevant changes"
This reverts commit 5152f65972.
* Undo irrelevant changes
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
* e2e: Support Circle
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
* Remove unused script
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
* TypeScript fixes
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
* TypeScript fixes
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
* Remove unused script
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
* More Drone support
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
* Remove unused script
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
* Fix build on Circle
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
* Remove TODO comment
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
179 lines
3.9 KiB
Go
179 lines
3.9 KiB
Go
package migrator
|
|
|
|
import (
|
|
"fmt"
|
|
"strconv"
|
|
"strings"
|
|
|
|
"github.com/lib/pq"
|
|
|
|
"github.com/grafana/grafana/pkg/util/errutil"
|
|
"xorm.io/xorm"
|
|
)
|
|
|
|
type Postgres struct {
|
|
BaseDialect
|
|
}
|
|
|
|
func NewPostgresDialect(engine *xorm.Engine) *Postgres {
|
|
d := Postgres{}
|
|
d.BaseDialect.dialect = &d
|
|
d.BaseDialect.engine = engine
|
|
d.BaseDialect.driverName = POSTGRES
|
|
return &d
|
|
}
|
|
|
|
func (db *Postgres) SupportEngine() bool {
|
|
return false
|
|
}
|
|
|
|
func (db *Postgres) Quote(name string) string {
|
|
return "\"" + name + "\""
|
|
}
|
|
|
|
func (b *Postgres) LikeStr() string {
|
|
return "ILIKE"
|
|
}
|
|
|
|
func (db *Postgres) AutoIncrStr() string {
|
|
return ""
|
|
}
|
|
|
|
func (db *Postgres) BooleanStr(value bool) string {
|
|
return strconv.FormatBool(value)
|
|
}
|
|
|
|
func (b *Postgres) Default(col *Column) string {
|
|
if col.Type == DB_Bool {
|
|
if col.Default == "0" {
|
|
return "FALSE"
|
|
}
|
|
return "TRUE"
|
|
}
|
|
return col.Default
|
|
}
|
|
|
|
func (db *Postgres) SqlType(c *Column) string {
|
|
var res string
|
|
switch t := c.Type; t {
|
|
case DB_TinyInt:
|
|
res = DB_SmallInt
|
|
return res
|
|
case DB_MediumInt, DB_Int, DB_Integer:
|
|
if c.IsAutoIncrement {
|
|
return DB_Serial
|
|
}
|
|
return DB_Integer
|
|
case DB_Serial, DB_BigSerial:
|
|
c.IsAutoIncrement = true
|
|
c.Nullable = false
|
|
res = t
|
|
case DB_Binary, DB_VarBinary:
|
|
return DB_Bytea
|
|
case DB_DateTime:
|
|
res = DB_TimeStamp
|
|
case DB_TimeStampz:
|
|
return "timestamp with time zone"
|
|
case DB_Float:
|
|
res = DB_Real
|
|
case DB_TinyText, DB_MediumText, DB_LongText:
|
|
res = DB_Text
|
|
case DB_NVarchar:
|
|
res = DB_Varchar
|
|
case DB_Uuid:
|
|
res = DB_Uuid
|
|
case DB_Blob, DB_TinyBlob, DB_MediumBlob, DB_LongBlob:
|
|
return DB_Bytea
|
|
case DB_Double:
|
|
return "DOUBLE PRECISION"
|
|
default:
|
|
if c.IsAutoIncrement {
|
|
return DB_Serial
|
|
}
|
|
res = t
|
|
}
|
|
|
|
var hasLen1 = (c.Length > 0)
|
|
var hasLen2 = (c.Length2 > 0)
|
|
if hasLen2 {
|
|
res += "(" + strconv.Itoa(c.Length) + "," + strconv.Itoa(c.Length2) + ")"
|
|
} else if hasLen1 {
|
|
res += "(" + strconv.Itoa(c.Length) + ")"
|
|
}
|
|
return res
|
|
}
|
|
|
|
func (db *Postgres) IndexCheckSql(tableName, indexName string) (string, []interface{}) {
|
|
args := []interface{}{tableName, indexName}
|
|
sql := "SELECT 1 FROM " + db.Quote("pg_indexes") + " WHERE" + db.Quote("tablename") + "=? AND " + db.Quote("indexname") + "=?"
|
|
return sql, args
|
|
}
|
|
|
|
func (db *Postgres) DropIndexSql(tableName string, index *Index) string {
|
|
quote := db.Quote
|
|
idxName := index.XName(tableName)
|
|
return fmt.Sprintf("DROP INDEX %v CASCADE", quote(idxName))
|
|
}
|
|
|
|
func (db *Postgres) UpdateTableSql(tableName string, columns []*Column) string {
|
|
var statements = []string{}
|
|
|
|
for _, col := range columns {
|
|
statements = append(statements, "ALTER "+db.Quote(col.Name)+" TYPE "+db.SqlType(col))
|
|
}
|
|
|
|
return "ALTER TABLE " + db.Quote(tableName) + " " + strings.Join(statements, ", ") + ";"
|
|
}
|
|
|
|
func (db *Postgres) CleanDB() error {
|
|
sess := db.engine.NewSession()
|
|
defer sess.Close()
|
|
|
|
if _, err := sess.Exec("DROP SCHEMA public CASCADE;"); err != nil {
|
|
return errutil.Wrap("failed to drop schema public", err)
|
|
}
|
|
|
|
if _, err := sess.Exec("CREATE SCHEMA public;"); err != nil {
|
|
return errutil.Wrap("failed to create schema public", err)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (db *Postgres) isThisError(err error, errcode string) bool {
|
|
if driverErr, ok := err.(*pq.Error); ok {
|
|
if string(driverErr.Code) == errcode {
|
|
return true
|
|
}
|
|
}
|
|
|
|
return false
|
|
}
|
|
|
|
func (db *Postgres) ErrorMessage(err error) string {
|
|
if driverErr, ok := err.(*pq.Error); ok {
|
|
return driverErr.Message
|
|
}
|
|
return ""
|
|
}
|
|
|
|
func (db *Postgres) IsUniqueConstraintViolation(err error) bool {
|
|
return db.isThisError(err, "23505")
|
|
}
|
|
|
|
func (db *Postgres) IsDeadlock(err error) bool {
|
|
return db.isThisError(err, "40P01")
|
|
}
|
|
|
|
func (db *Postgres) PostInsertId(table string, sess *xorm.Session) error {
|
|
if table != "org" {
|
|
return nil
|
|
}
|
|
|
|
// sync primary key sequence of org table
|
|
if _, err := sess.Exec("SELECT setval('org_id_seq', (SELECT max(id) FROM org));"); err != nil {
|
|
return errutil.Wrapf(err, "failed to sync primary key for org table")
|
|
}
|
|
return nil
|
|
}
|