Merge pull request #12751 from ywk253100/200812_migration

Use a separated database table to store the data version
This commit is contained in:
Wenkai Yin(尹文开) 2020-08-14 12:52:52 +08:00 committed by GitHub
commit 3b7a2e11b4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 4 deletions

View File

@ -116,3 +116,15 @@ ALTER TABLE schedule DROP COLUMN IF EXISTS status;
UPDATE registry SET type = 'quay' WHERE type = 'quay-io';
ALTER TABLE artifact ADD COLUMN icon varchar(255);
CREATE TABLE IF NOT EXISTS data_migrations (
version int
);
INSERT INTO data_migrations (version) VALUES (
CASE
/*if the "extra_attrs" isn't null, it means that the deployment upgrades from v2.0*/
WHEN (SELECT Count(*) FROM artifact WHERE extra_attrs!='')>0 THEN 30
ELSE 0
END
);
ALTER TABLE schema_migrations DROP COLUMN IF EXISTS data_version;

View File

@ -42,7 +42,7 @@ func abstractArtData(ctx context.Context) error {
continue
}
for _, repo := range repos {
log.Debugf("abstracting artifact metadata under repository %s ....", repo.Name)
log.Infof("abstracting artifact metadata under repository %s ....", repo.Name)
arts, err := artifact.Mgr.List(ctx, &q.Query{
Keywords: map[string]interface{}{
"RepositoryID": repo.RepositoryID,
@ -62,7 +62,7 @@ func abstractArtData(ctx context.Context) error {
continue
}
}
log.Debugf("artifact metadata under repository %s abstracted", repo.Name)
log.Infof("artifact metadata under repository %s abstracted", repo.Name)
}
}

View File

@ -86,7 +86,7 @@ func getDataVersion(ctx context.Context) (int, error) {
return 0, err
}
var version int
if err = ormer.Raw("select data_version from schema_migrations").QueryRow(&version); err != nil {
if err = ormer.Raw("select version from data_migrations").QueryRow(&version); err != nil {
return 0, err
}
return version, nil
@ -97,6 +97,6 @@ func setDataVersion(ctx context.Context, version int) error {
if err != nil {
return err
}
_, err = ormer.Raw("update schema_migrations set data_version=?", version).Exec()
_, err = ormer.Raw("update data_migrations set version=?", version).Exec()
return err
}