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

Spike/migrations direct #4499

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions apps/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ subprojects { subproject ->
with nodeSpec
}

task movePyFiles(type: Copy) {
from "migrations"
into "${parent.buildDir}/generated/main/resources/" + project.name + "/migration"
}

task format(type: YarnTask, dependsOn: parent.yarn_install) {
if (!isCI) {
args = ['run', 'format']
Expand Down
13 changes: 13 additions & 0 deletions apps/nuxt3-ssr/migrations/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
certifi==2024.7.4
charset-normalizer==2.1.1
idna==3.7
numpy==1.26.3
pandas==2.2.2
python-dateutil==2.8.2
python-decouple==3.8
pytz==2022.7.1
requests==2.32.3
setuptools==70.0.0
six==1.16.0
molgenis_emx2_pyclient
urllib3==1.26.19
11 changes: 11 additions & 0 deletions apps/nuxt3-ssr/migrations/version1/migrate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from molgenis_emx2_pyclient import Client

username = 'admin'
password = 'admin'

# Initialize the client as a context manager
with Client(url='http://localhost:8080') as client:
# Apply the 'signin' method with the username and password
client.signin(username, password)

# Perform other tasks
18 changes: 0 additions & 18 deletions apps/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7034,15 +7034,6 @@ handlebars@^4.7.7, handlebars@^4.7.8:
optionalDependencies:
uglify-js "^3.1.4"

happy-dom@15.10.1:
version "15.10.1"
resolved "https://registry.yarnpkg.com/happy-dom/-/happy-dom-15.10.1.tgz#db49321a7af97d8c18c45622de2817b382ac7595"
integrity sha512-FuGnj/qIB4QnBL6fWmD7Wnh6STxevLgOVWB6+nopDGgWG1+t9CXkNB2ldZ+iqwD2UKxD2D0SU8el8A6AX6Q1+g==
dependencies:
entities "^4.5.0"
webidl-conversions "^7.0.0"
whatwg-mimetype "^3.0.0"

happy-dom@15.10.2:
version "15.10.2"
resolved "https://registry.yarnpkg.com/happy-dom/-/happy-dom-15.10.2.tgz#14ae6652d1a80d2611e3f5832cb61ab5e2d1b539"
Expand All @@ -7052,15 +7043,6 @@ happy-dom@15.10.2:
webidl-conversions "^7.0.0"
whatwg-mimetype "^3.0.0"

happy-dom@15.7.4:
version "15.7.4"
resolved "https://registry.yarnpkg.com/happy-dom/-/happy-dom-15.7.4.tgz#05aade59c1d307336001b7004c76dfc6a829f220"
integrity sha512-r1vadDYGMtsHAAsqhDuk4IpPvr6N8MGKy5ntBo7tSdim+pWDxus2PNqOcOt8LuDZ4t3KJHE+gCuzupcx/GKnyQ==
dependencies:
entities "^4.5.0"
webidl-conversions "^7.0.0"
whatwg-mimetype "^3.0.0"

has-ansi@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/has-ansi/-/has-ansi-2.0.0.tgz#34f5049ce1ecdf2b0649af3ef24e45ed35416d91"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import static org.molgenis.emx2.ColumnType.BOOL;
import static org.molgenis.emx2.ColumnType.INT;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import org.molgenis.emx2.datamodels.BiobankDirectoryLoader;
import org.molgenis.emx2.datamodels.DataModels;
import org.molgenis.emx2.datamodels.PetStoreLoader;
Expand All @@ -28,7 +31,7 @@ public class RunMolgenisEmx2 {
(Boolean)
EnvironmentProperty.getParameter(Constants.MOLGENIS_EXCLUDE_PETSTORE_DEMO, false, BOOL);

public static void main(String[] args) {
public static void main(String[] args) throws IOException {
logger.info("Starting MOLGENIS EMX2 Software Version=" + Version.getVersion());

Integer port =
Expand Down Expand Up @@ -64,6 +67,54 @@ public static void main(String[] args) {
});

// start
logger.info("Before start");
MolgenisWebservice.start(port);

logger.info("After start");

String relativeMigrationFilePath = "./apps/nuxt3-ssr/migrations/version1/migrate.py";
String relativeRequirementsFilePath = "./apps/nuxt3-ssr/migrations/requirements.txt";
String migrationFilePathString = "/nuxt3-ssr/migration/version1/migrate.py";

// define commands (given tempDir as working directory)
String createVenvCommand = "python3 -m venv venv";
String activateCommand = "source venv/bin/activate";
String pipUpgradeCommand = "pip3 install --upgrade pip";
String installRequirementsCommand = "pip3 install -r " + relativeRequirementsFilePath;
String runScriptCommand = "python3 -u " + relativeMigrationFilePath;
String command =
String.join(
" && ",
createVenvCommand,
activateCommand,
pipUpgradeCommand,
installRequirementsCommand,
runScriptCommand);
logger.debug("Running migration script with command: {}", command);

// String runScriptCommand = "pwd";
ProcessBuilder builder = new ProcessBuilder("bash", "-c", command);
builder.redirectErrorStream(true);
Process process = builder.start();

// Read the process output
try (BufferedReader reader =
new BufferedReader(new InputStreamReader(process.getInputStream()))) {
String line;
while ((line = reader.readLine()) != null) {
// Log each line of output
logger.info("Process output: {}", line);
}
}

// Wait for the process to complete
int exitCode = 0;
try {
exitCode = process.waitFor();
} catch (InterruptedException e) {
logger.error("Error waiting for migration process to complete", e);
throw new RuntimeException(e);
}
logger.info("Migration process exited with code: {}", exitCode);
}
}