<commit_before>package migrations

import (
	. "github.com/grafana/grafana/pkg/services/sqlstore/migrator"
)

func addPublicDashboardMigration(mg *Migrator) {
	var dashboardPublicCfgV1 = Table{
		Name: "dashboard_public_config",
		Columns: []*Column{
			{Name: "uid", Type: DB_NVarchar, Length: 40, IsPrimaryKey: true},
			{Name: "dashboard_uid", Type: DB_NVarchar, Length: 40, Nullable: false},
			{Name: "org_id", Type: DB_BigInt, Nullable: false},

			{Name: "time_settings", Type: DB_Text, Nullable: true},
			{Name: "template_variables", Type: DB_MediumText, Nullable: true},

			{Name: "access_token", Type: DB_NVarchar, Length: 32, Nullable: false},

			{Name: "created_by", Type: DB_Int, Nullable: false},
			{Name: "updated_by", Type: DB_Int, Nullable: true},

			{Name: "created_at", Type: DB_DateTime, Nullable: false},
			{Name: "updated_at", Type: DB_DateTime, Nullable: true},

			{Name: "is_enabled", Type: DB_Bool, Nullable: false, Default: "0"},
		},
		Indices: []*Index{
			{Cols: []string{"uid"}, Type: UniqueIndex},
			{Cols: []string{"org_id", "dashboard_uid"}},
			{Cols: []string{"access_token"}, Type: UniqueIndex},
		},
	}

	// initial create table
	mg.AddMigration("create dashboard public config v1", NewAddTableMigration(dashboardPublicCfgV1))

	// recreate table - no dependencies and was created with incorrect pkey type
	addDropAllIndicesMigrations(mg, "v1", dashboardPublicCfgV1)
	mg.AddMigration("Drop old dashboard public config table", NewDropTableMigration("dashboard_public_config"))
	mg.AddMigration("recreate dashboard public config v1", NewAddTableMigration(dashboardPublicCfgV1))
	addTableIndicesMigrations(mg, "v1", dashboardPublicCfgV1)

	// recreate table - schema finalized for public dashboards v1
	addDropAllIndicesMigrations(mg, "v2", dashboardPublicCfgV1)
	mg.AddMigration("Drop public config table", NewDropTableMigration("dashboard_public_config"))
	mg.AddMigration("Recreate dashboard public config v2", NewAddTableMigration(dashboardPublicCfgV1))
	addTableIndicesMigrations(mg, "v2", dashboardPublicCfgV1)

	// rename table
	addTableRenameMigration(mg, "dashboard_public_config", "dashboard_public", "v2")
}<commit_msg>Add correct table definition for migrations for old dashboard_public schema (#51292)<commit_after>package migrations

import (
	. "github.com/grafana/grafana/pkg/services/sqlstore/migrator"
)

func addPublicDashboardMigration(mg *Migrator) {
	var dashboardPublicCfgV1 = Table{
		Name: "dashboard_public_config",
		Columns: []*Column{
			{Name: "uid", Type: DB_NVarchar, Length: 40, IsPrimaryKey: true},
			{Name: "dashboard_uid", Type: DB_NVarchar, Length: 40, Nullable: false},
			{Name: "org_id", Type: DB_BigInt, Nullable: false},
			{Name: "time_settings", Type: DB_Text, Nullable: false},
			{Name: "refresh_rate", Type: DB_Int, Nullable: false, Default: "30"},
			{Name: "template_variables", Type: DB_MediumText, Nullable: true},
		},
		Indices: []*Index{
			{Cols: []string{"uid"}, Type: UniqueIndex},
			{Cols: []string{"org_id", "dashboard_uid"}},
		},
	}

	var dashboardPublicCfgV2 = Table{
		Name: "dashboard_public_config",
		Columns: []*Column{
			{Name: "uid", Type: DB_NVarchar, Length: 40, IsPrimaryKey: true},
			{Name: "dashboard_uid", Type: DB_NVarchar, Length: 40, Nullable: false},
			{Name: "org_id", Type: DB_BigInt, Nullable: false},

			{Name: "time_settings", Type: DB_Text, Nullable: true},
			{Name: "template_variables", Type: DB_MediumText, Nullable: true},

			{Name: "access_token", Type: DB_NVarchar, Length: 32, Nullable: false},

			{Name: "created_by", Type: DB_Int, Nullable: false},
			{Name: "updated_by", Type: DB_Int, Nullable: true},

			{Name: "created_at", Type: DB_DateTime, Nullable: false},
			{Name: "updated_at", Type: DB_DateTime, Nullable: true},

			{Name: "is_enabled", Type: DB_Bool, Nullable: false, Default: "0"},
		},
		Indices: []*Index{
			{Cols: []string{"uid"}, Type: UniqueIndex},
			{Cols: []string{"org_id", "dashboard_uid"}},
			{Cols: []string{"access_token"}, Type: UniqueIndex},
		},
	}

	// initial create table
	mg.AddMigration("create dashboard public config v1", NewAddTableMigration(dashboardPublicCfgV1))

	// recreate table - no dependencies and was created with incorrect pkey type
	addDropAllIndicesMigrations(mg, "v1", dashboardPublicCfgV1)
	mg.AddMigration("Drop old dashboard public config table", NewDropTableMigration("dashboard_public_config"))
	mg.AddMigration("recreate dashboard public config v1", NewAddTableMigration(dashboardPublicCfgV1))
	addTableIndicesMigrations(mg, "v1", dashboardPublicCfgV1)

	// recreate table - schema finalized for public dashboards v1
	addDropAllIndicesMigrations(mg, "v2", dashboardPublicCfgV1)
	mg.AddMigration("Drop public config table", NewDropTableMigration("dashboard_public_config"))
	mg.AddMigration("Recreate dashboard public config v2", NewAddTableMigration(dashboardPublicCfgV2))
	addTableIndicesMigrations(mg, "v2", dashboardPublicCfgV2)

	// rename table
	addTableRenameMigration(mg, "dashboard_public_config", "dashboard_public", "v2")
}
{'fraction_non_alphanumeric': 0.13710317460317462, 'fraction_numerical': 0.011904761904761904, 'mean_word_length': 6.348396501457726, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '528000', 'n_tokens_mistral': 1791, 'n_tokens_neox': 1692, 'n_words': 410}