mirror of
https://github.com/goharbor/harbor.git
synced 2024-10-31 23:59:32 +01:00
Merge pull request #12751 from ywk253100/200812_migration
Use a separated database table to store the data version
This commit is contained in:
commit
3b7a2e11b4
@ -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;
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user