feat(apps): lots of more work on apps, changed app_plugin to app_settings in order to to confuse the app plugin model (definition) and app org settings

This commit is contained in:
Torkel Ödegaard
2016-01-10 21:37:11 +01:00
parent ab79348af5
commit c1e94e61d0
23 changed files with 272 additions and 220 deletions
@@ -8,27 +8,27 @@ import (
)
func init() {
bus.AddHandler("sql", GetAppPlugins)
bus.AddHandler("sql", UpdateAppPlugin)
bus.AddHandler("sql", GetAppSettings)
bus.AddHandler("sql", UpdateAppSettings)
}
func GetAppPlugins(query *m.GetAppPluginsQuery) error {
func GetAppSettings(query *m.GetAppSettingsQuery) error {
sess := x.Where("org_id=?", query.OrgId)
query.Result = make([]*m.AppPlugin, 0)
query.Result = make([]*m.AppSettings, 0)
return sess.Find(&query.Result)
}
func UpdateAppPlugin(cmd *m.UpdateAppPluginCmd) error {
func UpdateAppSettings(cmd *m.UpdateAppSettingsCmd) error {
return inTransaction2(func(sess *session) error {
var app m.AppPlugin
var app m.AppSettings
exists, err := sess.Where("org_id=? and type=?", cmd.OrgId, cmd.Type).Get(&app)
exists, err := sess.Where("org_id=? and app_id=?", cmd.OrgId, cmd.AppId).Get(&app)
sess.UseBool("enabled")
sess.UseBool("pinned")
if !exists {
app = m.AppPlugin{
Type: cmd.Type,
app = m.AppSettings{
AppId: cmd.AppId,
OrgId: cmd.OrgId,
Enabled: cmd.Enabled,
Pinned: cmd.Pinned,
@@ -2,14 +2,14 @@ package migrations
import . "github.com/grafana/grafana/pkg/services/sqlstore/migrator"
func addAppPluginMigration(mg *Migrator) {
func addAppSettingsMigration(mg *Migrator) {
var appPluginV2 = Table{
Name: "app_plugin",
appSettingsV1 := Table{
Name: "app_settings",
Columns: []*Column{
{Name: "id", Type: DB_BigInt, IsPrimaryKey: true, IsAutoIncrement: true},
{Name: "org_id", Type: DB_BigInt, Nullable: true},
{Name: "type", Type: DB_NVarchar, Length: 255, Nullable: false},
{Name: "app_id", Type: DB_NVarchar, Length: 255, Nullable: false},
{Name: "enabled", Type: DB_Bool, Nullable: false},
{Name: "pinned", Type: DB_Bool, Nullable: false},
{Name: "json_data", Type: DB_Text, Nullable: true},
@@ -17,12 +17,12 @@ func addAppPluginMigration(mg *Migrator) {
{Name: "updated", Type: DB_DateTime, Nullable: false},
},
Indices: []*Index{
{Cols: []string{"org_id", "type"}, Type: UniqueIndex},
{Cols: []string{"org_id", "app_id"}, Type: UniqueIndex},
},
}
mg.AddMigration("create app_plugin table v2", NewAddTableMigration(appPluginV2))
mg.AddMigration("create app_settings table v1", NewAddTableMigration(appSettingsV1))
//------- indexes ------------------
addTableIndicesMigrations(mg, "v2", appPluginV2)
addTableIndicesMigrations(mg, "v3", appSettingsV1)
}
@@ -18,7 +18,7 @@ func AddMigrations(mg *Migrator) {
addApiKeyMigrations(mg)
addDashboardSnapshotMigrations(mg)
addQuotaMigration(mg)
addAppPluginMigration(mg)
addAppSettingsMigration(mg)
addSessionMigration(mg)
}