Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

genetable version added to info api #11290

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
20 changes: 14 additions & 6 deletions docs/Updating-your-cBioPortal-installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,37 @@ As of release **1.1.0** cBioPortal has a Database schema update mechanism which

## First time

The first time you update from release **1.0.4** (or lower) to release **1.1.0** (or higher), you should get a an error banner page after restarting your webserver. The error should state something like:
The first time you update from release **1.0.4** (or lower) to release **1.1.0** (or higher), you should get a an error banner page after restarting your webserver. The error should state something like:

```
Current DB schema version: xxx
Current DB schema version: xxx
DB schema version expected by Portal: yyy
```
where `xxx` and `yyy` will be different version numbers.

If you get `DB version expected by Portal: 0` (i.e. you are building the new release from source), you need to add a new property to your `application.properties` file which is needed for this check.
where `xxx` and `yyy` will be different version numbers.

If you get `DB version expected by Portal: 0` (i.e. you are building the new release from source), you need to add a new property to your `application.properties` file which is needed for this check.

#### Step1

In your `application.properties` file (e.g. `<your_cbioportal_dir>/src/main/resources/application.properties`) add the following property:

```
# this is the *expected* DB version (expected by the code). Don't set it manually, it is filled by maven:
db.version=${db.version}
genetable.version=${genetable.version}
```

#### Step2

Compile your code again. After restarting the webserver the page should now state something like: `DB version expected by Portal: 1.1.0` (or higher), while the DB version remains as `Current DB version: -1`.
Compile your code again. After restarting the webserver the page should now state something like: `DB version expected by Portal: 1.1.0` (or higher), while the DB version remains as `Current DB version: -1`.

## Running the migration script

First, make sure you have the DB connection properties correctly set in your application.properties file (see [DB connection settings here](/deployment/customization/application.properties-Reference.md#database-settings)).

**Dependencies:** the migration script is a Python script that depends on the `mysqlclient` library. If necessary, you can install it with the following commands (example for Ubuntu):

```console
sudo apt-get install python3-dev default-libmysqlclient-dev
sudo python3 -m pip install mysqlclient
Expand All @@ -42,16 +46,20 @@ For macOS, try the following:
brew install mysql-connector-c
sudo python3 -m pip install mysqlclient
```

and see <https://github.com/PyMySQL/mysqlclient-python/blob/master/README.md#prerequisites>
if problems occur during installation.

To run the migration script first go to the scripts folder
`<your_cbioportal_dir>/core/src/main/scripts`
`<your_cbioportal_dir>/core/src/main/scripts`
and then run the following command:

```console
$ python migrate_db.py
```

This should result in the following output:

```console
WARNING: This script will alter your database! Be sure to back up your data before running.
Continue running DB migration? (y/n) y
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

<!-- THIS SHOULD BE KEPT IN SYNC TO VERSION IN CGDS.SQL -->
<db.version>2.13.1</db.version>

<genetable.version>hgnc_v2023.10.1</genetable.version>
<!-- Version properties for dependencies that should have same version. -->
<!-- The rest can be set in the dependencyManagement section -->
<spring.social.version>1.1.6.RELEASE</spring.social.version>
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/org/cbioportal/model/Info.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ public class Info implements Serializable {
@NotNull
private String dbVersion;
@NotNull
private String genetableVersion;
@NotNull
private String gitBranch;
@NotNull
private String gitCommitId;
Expand Down Expand Up @@ -42,6 +44,14 @@ public String getGitCommitId() {
return this.gitCommitId;
}

public String getGenetableVersion(){
return this.genetableVersion;
}

public void setGenetableVersion(String genetableVersion){
this.genetableVersion = genetableVersion;
}

public void setGitCommitId(String gitCommitId) {
this.gitCommitId = gitCommitId;
}
Expand Down
9 changes: 8 additions & 1 deletion src/main/java/org/cbioportal/web/InfoController.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ public class InfoController {

@Value("${db.version}")
private String dbVersion;

@Value("${genetable.version}")
private String genetableVersion;

@Value("${git.branch:not set}")
private String gitBranch;
Expand Down Expand Up @@ -59,15 +62,18 @@ public class InfoController {
@Value("${git.dirty:not set}")
private String gitDirty;



@RequestMapping(value = "/api/info", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@Operation(description = "Get information about the running instance")
@ApiResponse(responseCode = "200", description = "OK",
content = @Content(schema = @Schema(implementation = Info.class)))
public ResponseEntity<Info> getInfo() {

Info info = new Info();
info.setPortalVersion(portalVersion);
info.setDbVersion(dbVersion);
info.setGenetableVersion(genetableVersion);
info.setGitBranch(gitBranch);
info.setGitCommitId(gitCommitId);
info.setGitCommitIdDescribe(gitCommitIdDescribe);
Expand All @@ -77,6 +83,7 @@ public ResponseEntity<Info> getInfo() {
info.setGitCommitMessageUserEmail(gitCommitMessageUserEmail);
info.setGitCommitMessageUserName(gitCommitMessageUserName);
info.isGitDirty(Boolean.valueOf(gitDirty));

return new ResponseEntity<>(info, HttpStatus.OK);
}
}
5 changes: 3 additions & 2 deletions src/main/resources/db-scripts/cgds.sql
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,8 @@ CREATE TABLE `allele_specific_copy_number` (
-- --------------------------------------------------------
CREATE TABLE `info` (
`DB_SCHEMA_VERSION` varchar(24),
`GENESET_VERSION` varchar(24)
`GENESET_VERSION` varchar(24),
`GENE_TABLE_VERSION` varchar(24)
);

-- --------------------------------------------------------
Expand Down Expand Up @@ -755,5 +756,5 @@ CREATE TABLE `resource_study` (
);

-- THIS MUST BE KEPT IN SYNC WITH db.version PROPERTY IN pom.xml
INSERT INTO info VALUES ('2.13.1', NULL);
INSERT INTO info VALUES ('2.13.1','hgnc_v2023.10.1', NULL );

2 changes: 2 additions & 0 deletions src/main/resources/db-scripts/migration.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1027,4 +1027,6 @@ ALTER TABLE `clinical_event_data` MODIFY COLUMN `VALUE` varchar(3000) NOT NULL;
CREATE INDEX idx_clinical_event_key ON clinical_event_data (`KEY`);
CREATE INDEX idx_clinical_event_value ON clinical_event_data (`VALUE`);
CREATE INDEX idx_sample_stable_id ON sample (`STABLE_ID`);
ALTER TABLE `info` ADD COLUMN `GENE_TABLE_VERSION` varchar(24);
UPDATE `info` SET `GENE_TABLE_VERSION`="hgnc_v2023.10.1";
UPDATE `info` SET `DB_SCHEMA_VERSION`="2.13.1";
4,552 changes: 4,551 additions & 1 deletion src/main/resources/legacy-api.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion src/main/resources/maven.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[email protected]@
[email protected]@
# this is the *expected* DB version (expected by the code). Don't set it manually, it is filled by maven:
[email protected]@
[email protected]@
[email protected]@
6 changes: 4 additions & 2 deletions src/test/java/org/cbioportal/web/InfoControllerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
@ContextConfiguration(classes = {InfoController.class, TestConfig.class})
@TestPropertySource(properties = {
"portal.version=test_portal_version",
"db.version=test_db_version"
"db.version=test_db_version",
"genetable.version=test_genetable_version"
})
public class InfoControllerTest {

Expand All @@ -35,6 +36,7 @@ public void getInfo() throws Exception {
.andExpect(MockMvcResultMatchers.status().isOk())
.andExpect(MockMvcResultMatchers.content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
.andExpect(MockMvcResultMatchers.jsonPath("$.portalVersion").value("test_portal_version"))
.andExpect(MockMvcResultMatchers.jsonPath("$.dbVersion").value("test_db_version"));
.andExpect(MockMvcResultMatchers.jsonPath("$.dbVersion").value("test_db_version"))
.andExpect(MockMvcResultMatchers.jsonPath("$.genetableVersion").value("test_genetable_version"));
}
}
1 change: 1 addition & 0 deletions src/test/resources/maven.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
portal.version=test_portal_version
db.version=test_db_version
app.version=test_app_version
genetable.version=test_genetable_version
54 changes: 39 additions & 15 deletions test/test_db_version.sh
Original file line number Diff line number Diff line change
@@ -1,30 +1,54 @@
#!/usr/bin/env bash
# halt on error
# Halt on error
set -e
# script dir

# Script directory
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
#colors

# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m'

echo "Making sure all db versions are the same in cgds.sql, pom.xml and migration.sql"
echo "Checking db and genetable versions in pom.xml, cgds.sql, and migration.sql"

# Fetch db version from pom.xml
POM_DB_VERSION=$(grep '<db.version>' ${DIR}/../pom.xml | cut -d'>' -f2 | cut -d'<' -f1)
echo "pom.xml db version is $POM_DB_VERSION"

# Fetch geneTable version from pom.xml
POM_GENE_TABLE_VERSION=$(grep '<genetable.version>' ${DIR}/../pom.xml | cut -d'>' -f2 | cut -d'<' -f1)
echo "pom.xml genetable version is $POM_GENE_TABLE_VERSION"

POM_DB_VERSION=$(grep db.version ${DIR}/../pom.xml | cut -d'>' -f2 | cut -d'<' -f1)
echo pom.xml db version is $POM_DB_VERSION
# Fetch db version from cgds.sql
CGDS_DB_SQL_VERSION=$(grep "INSERT INTO info" ${DIR}/../src/main/resources/db-scripts/cgds.sql | cut -d"'" -f2 | cut -d"'" -f1)
echo "src/main/resources/db-scripts/cgds.sql db version is $CGDS_DB_SQL_VERSION"

CGDS_DB_SQL_VERSION=$(grep 'INSERT INTO info' ${DIR}/../src/main/resources/db-scripts/cgds.sql | cut -d"'" -f2 | cut -d"'" -f1)
echo src/main/resources/db-scripts/cgds.sql db version is $CGDS_DB_SQL_VERSION
# Fetch geneTable version from cgds.sql
CGDS_GENE_TABLE_VERSION=$(grep "INSERT INTO info" ${DIR}/../src/main/resources/db-scripts/cgds.sql | grep "genetable" | cut -d"'" -f4)
echo "src/main/resources/db-scripts/cgds.sql genetable version is $CGDS_GENE_TABLE_VERSION"

# Fetch db version from migration.sql
MIGRATION_DB_VERSION=$(grep 'UPDATE `info`' ${DIR}/../src/main/resources/db-scripts/migration.sql | tail -1 | cut -d '"' -f2 | cut -d'"' -f1)
echo src/main/resources/db-scripts/migration.sql db version is $MIGRATION_DB_VERSION
echo "src/main/resources/db-scripts/migration.sql db version is $MIGRATION_DB_VERSION"

# Fetch geneTable version from migration.sql
MIGRATION_GENE_TABLE_VERSION=$(grep 'UPDATE `info`' ${DIR}/../src/main/resources/db-scripts/migration.sql | tail -1 | cut -d '"' -f4 | cut -d'"' -f1)
echo "src/main/resources/db-scripts/migration.sql genetable version is $MIGRATION_GENE_TABLE_VERSION"

# Verify db versions match
if [ "$POM_DB_VERSION" == "$CGDS_DB_SQL_VERSION" ] && [ "$CGDS_DB_SQL_VERSION" == "$MIGRATION_DB_VERSION" ]; then
echo -e "${GREEN}db versions match${NC}"
else
echo -e "${RED}db versions mismatch${NC}"
exit 1
fi

if [ "$POM_DB_VERSION" == "$CGDS_DB_SQL_VERSION" ] && [ "$CGDS_DB_SQL_VERSION" == "$MIGRATION_DB_VERSION" ]
then
echo -e "${GREEN}db versions match${NC}";
exit 0;
# Verify geneTable versions match
if [ "$POM_GENE_TABLE_VERSION" == "$CGDS_GENE_TABLE_VERSION" ] && [ "$CGDS_GENE_TABLE_VERSION" == "$MIGRATION_GENE_TABLE_VERSION" ]; then
echo -e "${GREEN}genetable versions match${NC}"
else
echo -e "${RED}db versions mismatch${NC}";
exit 1;
echo -e "${RED}genetable versions mismatch${NC}"
exit 1
fi