Uploaded image for project: 'Dev - Nexus Repo'
  1. Dev - Nexus Repo
  2. NEXUS-34771

DB migrator 3.41.0 can not migrate to PostgreSQL without --force=true

    Details

    • Story Points:
      3
    • Sprint:
      NXRM Optimus Sprint 46
    • Notability:
      2

      Description

      ISSUE:

      Noticed 3.41.0 DB migrator jar fails to migrate the nexus.mv.db file.

      $ java -Xms4G -Xmx4G -jar ./nexus-db-migrator-3.41.0-01.jar --migration_type=h2_to_postgres --db_url="jdbc:postgresql://localhost:5432/nxrm?gssEncMode=disable&user=nxrm&password=nxrm123"
      09:38:20 [main] WARN  c.s.n.d.migrator.MigratorApplication - Please ensure any Nexus Repository instance has been gracefully shut down before proceeding.
      09:38:20 [main] INFO  c.s.n.d.migrator.MigratorApplication - Do you want to continue [y/n]?
      y
      09:38:21 [main] INFO  c.s.n.d.migrator.MigratorApplication - --content_migration parameter is absent. Setting it to true.
      09:38:21 [main] INFO  c.s.n.d.migrator.MigratorApplication - Force parameter wasn't found. Setting it to false by default.
      09:38:21 [main] INFO  c.s.n.d.migrator.MigratorApplication - ------------------------------------------------------------
      09:38:21 [main] INFO  c.s.n.d.migrator.MigratorApplication - Java version: AdoptOpenJDK 11.0.10
      09:38:21 [main] INFO  c.s.n.d.migrator.MigratorApplication - JVM arguments: -Xms4G -Xmx4G
      09:38:21 [main] INFO  c.s.n.d.migrator.MigratorApplication - Migrator arguments: --migration_type=h2_to_postgres --db_url=jdbc:postgresql://localhost:5432/nxrm?gssEncMode=disable&user=nxrm&password=**** --content_migration=true --force=false
      09:38:21 [main] INFO  c.s.n.d.migrator.MigratorApplication - ------------------------------------------------------------
      09:38:22 [main] INFO  c.s.n.d.migrator.MigratorApplication - Starting MigratorApplication v3.41.0-01 using Java 11.0.10 on Hajimes-MacBook-Pro.local with PID 7597 (/Volumes/Samsung_T5/hajime/nexus_executable_cache/nexus-db-migrator-3.41.0-01.jar started by hosako in /private/tmp/sptBoot/support-20220817-162910-2_tmp/sonatype-work/nexus3/db)
      09:38:22 [main] INFO  c.s.n.d.migrator.MigratorApplication - No active profile set, falling back to 1 default profile: "default"
      09:38:23 [main] INFO  o.s.b.c.r.s.JobRepositoryFactoryBean - No database type set, using meta data indicating: POSTGRES
      09:38:23 [main] INFO  c.s.n.d.migrator.MigratorApplication - Started MigratorApplication in 2.065 seconds (JVM running for 4.154)
      09:38:23 [main] INFO  o.s.b.a.b.JobLauncherApplicationRunner - Running default command line with: [--migration_type=h2_to_postgres, --db_url=jdbc:postgresql://localhost:5432/nxrm?gssEncMode=disable&user=nxrm&password=nxrm123, --content_migration=true, --force=false]
      09:38:23 [main] INFO  o.s.b.a.l.ConditionEvaluationReportLoggingListener -
      
      Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
      09:38:23 [main] ERROR o.s.boot.SpringApplication - Application run failed
      java.lang.IllegalStateException: Failed to execute ApplicationRunner
      	at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:771)
      	at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:758)
      	at org.springframework.boot.SpringApplication.run(SpringApplication.java:310)
      	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1312)
      	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1301)
      	at com.sonatype.nexus.db.migrator.MigratorApplication.main(MigratorApplication.java:91)
      Caused by: com.sonatype.nexus.db.migrator.exception.MigratorJobParametersInvalidException: Target database has content. If you want to delete all content in your target database, you have to rerun migration with '--force=true' flag.
      

      NOTE: Above was just after creating the new database "nxrm".
      NOTE2: Later noticed even OrientDB to PostgreSQL, it fails with same error.

      EXPECTATION:

      It should never encourage users to casually use the "--force" option.
      This change could mislead the users because users would think they would always need to use "--force" option, which is very dangerous option as it tries to drop tables, so that if a user accidentally used a wrong database, it would cause a disaster situation.

      CAUSE

      TargetDatabaseValidator has the following validation:

          return !Objects.equals(count, BATCH_TABLES_COUNT);
      

      If my understanding is correct, above would return true when "SELECT COUNT( * ) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'PUBLIC';" returns "0".

      WORKAROUND:

      Follow the error message and use "--force=true", or to be safe, just change the command to use 3.40.1-01 one:

      $ java -Xms4G -Xmx4G -jar ./nexus-db-migrator-3.40.1-01.jar --migration_type=h2_to_postgres --db_url="jdbc:postgresql://localhost:5432/nxrm?gssEncMode=disable&user=nxrm&password=nxrm123"
      09:40:05 [main] WARN  c.s.n.d.migrator.MigratorApplication - Please ensure any NXRM instance has been gracefully shut down before proceeding. Do you want to continue [y/n]?
      y
      ... (snip) ...
      09:40:12 [main] INFO  c.s.n.d.m.l.ProvidingJobInfoListener - Migration job finished at Fri Aug 19 09:40:12 AEST 2022
      09:40:12 [main] INFO  c.s.n.d.m.l.ProvidingJobInfoListener - Migration job took 2 seconds to execute
      09:40:12 [main] INFO  c.s.n.d.m.l.ProvidingJobInfoListener - 401 records were processed
      09:40:12 [main] INFO  c.s.n.d.m.l.ProvidingJobInfoListener - 22 records were filtered
      09:40:12 [main] INFO  c.s.n.d.m.l.ProvidingJobInfoListener - 0 records were skipped
      09:40:12 [main] INFO  c.s.n.d.m.l.ProvidingJobInfoListener - 401 records were migrated
      09:40:12 [main] INFO  c.s.n.d.m.l.ProvidingJobInfoListener - Created 'Rebuild repository browse' and 'Rebuild repository search' tasks. They will automatically one-time run after starting your Nexus Repository instance.
      09:40:12 [main] INFO  c.s.n.d.m.l.ProvidingJobInfoListener - Migrated only early access formats: [APT, COCOAPODS, CONAN, CONDA, DOCKER, GITLFS, GO, HELM, MAVEN2, NPM, NUGET, P2, PYPI, R, RAW, RUBYGEMS, YUM]
      

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              sshamrai Sergii Shamrai
              Reporter:
              hosako Hajime Osako
              Last Updated By:
              Andrew Allred Andrew Allred
              Team:
              NXRM - Optimus
              Owner:
              Sergii Shamrai Sergii Shamrai
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Date of First Response:

                  tigCommentSecurity.panel-title