mirror of
https://github.com/aykhans/slash-e.git
synced 2025-04-18 21:19:44 +00:00
chore: add visibility migrate scripts
This commit is contained in:
parent
f276c979fa
commit
3937abb17b
11
store/migration/postgres/prod/1.0/00__visibility.sql
Normal file
11
store/migration/postgres/prod/1.0/00__visibility.sql
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
ALTER TABLE shortcut DROP CONSTRAINT IF EXISTS shortcut_visibility_check;
|
||||||
|
|
||||||
|
ALTER TABLE shortcut ALTER COLUMN visibility SET DEFAULT 'WORKSPACE';
|
||||||
|
|
||||||
|
UPDATE shortcut SET visibility = 'WORKSPACE' WHERE visibility = 'PRIVATE';
|
||||||
|
|
||||||
|
ALTER TABLE collection DROP CONSTRAINT IF EXISTS collection_visibility_check;
|
||||||
|
|
||||||
|
ALTER TABLE collection ALTER COLUMN visibility SET DEFAULT 'WORKSPACE';
|
||||||
|
|
||||||
|
UPDATE collection SET visibility = 'WORKSPACE' WHERE visibility = 'PRIVATE';
|
90
store/migration/sqlite/prod/1.0/00__visibility.sql
Normal file
90
store/migration/sqlite/prod/1.0/00__visibility.sql
Normal file
@ -0,0 +1,90 @@
|
|||||||
|
UPDATE shortcut SET visibility = 'WORKSPACE' WHERE visibility = 'PRIVATE';
|
||||||
|
|
||||||
|
ALTER TABLE shortcut RENAME TO shortcut_old;
|
||||||
|
|
||||||
|
CREATE TABLE shortcut (
|
||||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
creator_id INTEGER NOT NULL,
|
||||||
|
created_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')),
|
||||||
|
updated_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')),
|
||||||
|
row_status TEXT NOT NULL CHECK (row_status IN ('NORMAL', 'ARCHIVED')) DEFAULT 'NORMAL',
|
||||||
|
name TEXT NOT NULL UNIQUE,
|
||||||
|
link TEXT NOT NULL,
|
||||||
|
title TEXT NOT NULL DEFAULT '',
|
||||||
|
description TEXT NOT NULL DEFAULT '',
|
||||||
|
visibility TEXT NOT NULL DEFAULT 'WORKSPACE',
|
||||||
|
tag TEXT NOT NULL DEFAULT '',
|
||||||
|
og_metadata TEXT NOT NULL DEFAULT '{}'
|
||||||
|
);
|
||||||
|
|
||||||
|
INSERT INTO shortcut (
|
||||||
|
id,
|
||||||
|
creator_id,
|
||||||
|
created_ts,
|
||||||
|
updated_ts,
|
||||||
|
row_status,
|
||||||
|
name,
|
||||||
|
link,
|
||||||
|
title,
|
||||||
|
description,
|
||||||
|
visibility,
|
||||||
|
tag,
|
||||||
|
og_metadata
|
||||||
|
)
|
||||||
|
SELECT
|
||||||
|
id,
|
||||||
|
creator_id,
|
||||||
|
created_ts,
|
||||||
|
updated_ts,
|
||||||
|
row_status,
|
||||||
|
name,
|
||||||
|
link,
|
||||||
|
title,
|
||||||
|
description,
|
||||||
|
visibility,
|
||||||
|
tag,
|
||||||
|
og_metadata
|
||||||
|
FROM shortcut_old;
|
||||||
|
|
||||||
|
DROP TABLE shortcut_old;
|
||||||
|
|
||||||
|
UPDATE collection SET visibility = 'WORKSPACE' WHERE visibility = 'PRIVATE';
|
||||||
|
|
||||||
|
ALTER TABLE collection RENAME TO collection_old;
|
||||||
|
|
||||||
|
CREATE TABLE collection (
|
||||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
creator_id INTEGER NOT NULL,
|
||||||
|
created_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')),
|
||||||
|
updated_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')),
|
||||||
|
name TEXT NOT NULL UNIQUE,
|
||||||
|
title TEXT NOT NULL DEFAULT '',
|
||||||
|
description TEXT NOT NULL DEFAULT '',
|
||||||
|
shortcut_ids INTEGER[] NOT NULL,
|
||||||
|
visibility TEXT NOT NULL DEFAULT 'WORKSPACE'
|
||||||
|
);
|
||||||
|
|
||||||
|
INSERT INTO collection (
|
||||||
|
id,
|
||||||
|
creator_id,
|
||||||
|
created_ts,
|
||||||
|
updated_ts,
|
||||||
|
name,
|
||||||
|
title,
|
||||||
|
description,
|
||||||
|
shortcut_ids,
|
||||||
|
visibility
|
||||||
|
)
|
||||||
|
SELECT
|
||||||
|
id,
|
||||||
|
creator_id,
|
||||||
|
created_ts,
|
||||||
|
updated_ts,
|
||||||
|
name,
|
||||||
|
title,
|
||||||
|
description,
|
||||||
|
shortcut_ids,
|
||||||
|
visibility
|
||||||
|
FROM collection_old;
|
||||||
|
|
||||||
|
DROP TABLE collection_old;
|
@ -263,13 +263,17 @@ func (s *Store) normalizedMigrationHistoryList(ctx context.Context) error {
|
|||||||
sort.Sort(common.SortVersion(versions))
|
sort.Sort(common.SortVersion(versions))
|
||||||
latestVersion := versions[len(versions)-1]
|
latestVersion := versions[len(versions)-1]
|
||||||
latestMinorVersion := common.GetMinorVersion(latestVersion)
|
latestMinorVersion := common.GetMinorVersion(latestVersion)
|
||||||
|
// If the latest version is greater than or equal to 1.0, the migration history is already normalized.
|
||||||
|
if common.IsVersionGreaterOrEqualThan(latestMinorVersion, "1.0") {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
schemaVersionMap := map[string]string{}
|
|
||||||
filePaths, err := fs.Glob(migrationFS, fmt.Sprintf("%s*/*.sql", s.getMigrationBasePath()))
|
filePaths, err := fs.Glob(migrationFS, fmt.Sprintf("%s*/*.sql", s.getMigrationBasePath()))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "failed to read migration files")
|
return errors.Wrap(err, "failed to read migration files")
|
||||||
}
|
}
|
||||||
sort.Strings(filePaths)
|
sort.Strings(filePaths)
|
||||||
|
schemaVersionMap := map[string]string{}
|
||||||
for _, filePath := range filePaths {
|
for _, filePath := range filePaths {
|
||||||
fileSchemaVersion, err := s.getSchemaVersionOfMigrateScript(filePath)
|
fileSchemaVersion, err := s.getSchemaVersionOfMigrateScript(filePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -283,7 +287,6 @@ func (s *Store) normalizedMigrationHistoryList(ctx context.Context) error {
|
|||||||
return errors.Wrap(err, "failed to get current schema version")
|
return errors.Wrap(err, "failed to get current schema version")
|
||||||
}
|
}
|
||||||
schemaVersionMap[common.GetMinorVersion(currentSchemaVersion)] = currentSchemaVersion
|
schemaVersionMap[common.GetMinorVersion(currentSchemaVersion)] = currentSchemaVersion
|
||||||
|
|
||||||
latestSchemaVersion := schemaVersionMap[latestMinorVersion]
|
latestSchemaVersion := schemaVersionMap[latestMinorVersion]
|
||||||
if latestSchemaVersion == "" {
|
if latestSchemaVersion == "" {
|
||||||
return errors.Errorf("latest schema version not found")
|
return errors.Errorf("latest schema version not found")
|
||||||
|
@ -13,5 +13,5 @@ func TestGetCurrentSchemaVersion(t *testing.T) {
|
|||||||
|
|
||||||
currentSchemaVersion, err := ts.GetCurrentSchemaVersion()
|
currentSchemaVersion, err := ts.GetCurrentSchemaVersion()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, "1.0.0", currentSchemaVersion)
|
require.Equal(t, "1.0.1", currentSchemaVersion)
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,7 @@ func GetTestingProfile(t *testing.T) *profile.Profile {
|
|||||||
|
|
||||||
// Get a temporary directory for the test data.
|
// Get a temporary directory for the test data.
|
||||||
dir := t.TempDir()
|
dir := t.TempDir()
|
||||||
mode := "dev"
|
mode := "prod"
|
||||||
port := getUnusedPort()
|
port := getUnusedPort()
|
||||||
driver := getDriverFromEnv()
|
driver := getDriverFromEnv()
|
||||||
dsn := os.Getenv("DSN")
|
dsn := os.Getenv("DSN")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user