-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new schema_version endpoint (#116)
* add new schema_version endpoint * update sorting
- Loading branch information
Showing
9 changed files
with
132 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,85 @@ | ||
package models | ||
|
||
import "github.com/uc-cdis/cohort-middleware/version" | ||
import ( | ||
"time" | ||
|
||
"github.com/uc-cdis/cohort-middleware/db" | ||
"github.com/uc-cdis/cohort-middleware/utils" | ||
"github.com/uc-cdis/cohort-middleware/version" | ||
) | ||
|
||
type Version struct { | ||
GitCommit string | ||
GitVersion string | ||
} | ||
|
||
type DbSchemaVersion struct { | ||
AtlasSchemaVersion string | ||
DataSchemaVersion int | ||
} | ||
|
||
type SchemaVersion struct { | ||
InstalledRank int | ||
Version string | ||
Description string | ||
Type string | ||
Script string | ||
Checksum int | ||
InstalledBy string | ||
InstalledOn time.Time | ||
ExecutionTime int | ||
Success bool | ||
} | ||
|
||
type VersionInfo struct { | ||
Version int | ||
AppliedOn time.Time | ||
Description string | ||
} | ||
|
||
func (h Version) GetVersion() *Version { | ||
return &Version{GitCommit: version.GitCommit, GitVersion: version.GitVersion} | ||
} | ||
|
||
func (h Version) GetSchemaVersion() *DbSchemaVersion { | ||
dbSchemaVersion := &DbSchemaVersion{"error", -1} | ||
|
||
atlasDb := db.GetAtlasDB().Db | ||
var atlasSchemaVersion *SchemaVersion | ||
query := atlasDb.Model(&SchemaVersion{}). | ||
Limit(1). | ||
Select("version"). | ||
Order("installed_rank desc") | ||
|
||
query, cancel := utils.AddTimeoutToQuery(query) | ||
defer cancel() | ||
meta_result := query.Scan(&atlasSchemaVersion) | ||
if meta_result.Error == nil { | ||
dbSchemaVersion.AtlasSchemaVersion = atlasSchemaVersion.Version | ||
} | ||
|
||
var source = new(Source) | ||
sources, _ := source.GetAllSources() | ||
if len(sources) < 1 { | ||
panic("Error: No data source found") | ||
} else if len(sources) > 1 { | ||
panic("More than one data source! Exiting") | ||
} | ||
var dataSourceModel = new(Source) | ||
dboDataSource := dataSourceModel.GetDataSource(sources[0].SourceId, Dbo) | ||
|
||
var versionInfo *VersionInfo | ||
query = dboDataSource.Db.Table(dboDataSource.Schema + ".versioninfo"). | ||
Limit(1). | ||
Select("Version"). | ||
Order("Version Desc") | ||
|
||
query, cancel = utils.AddTimeoutToQuery(query) | ||
defer cancel() | ||
meta_result = query.Scan(&versionInfo) | ||
if meta_result.Error == nil { | ||
dbSchemaVersion.DataSchemaVersion = versionInfo.Version | ||
} | ||
|
||
return dbSchemaVersion | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters