简体   繁体   English

如果退出,activejdbc 迁移器会强制创建 `schema_version` 表

[英]activejdbc migrator force to create `schema_version` table if it exits

Today I am going to setup another development env by dumping the demo data from one server and restoring to another one.今天,我将通过从一台服务器转储演示数据并恢复到另一台服务器来设置另一个开发环境。 Also I copy the code base to the development server.我还将代码库复制到开发服务器。 When I run mvn validate which will invoke migration, it outputs当我运行mvn validate这将调用迁移时,它输出

[INFO] Scanning for projects...
[INFO]
[INFO] ----------------------< com.ft:xjobs-server >-----------------------
[INFO] Building API server for xJobs service 0.2-SNAPSHOT
[INFO] --------------------------------[ war ]---------------------------------
[INFO]
[INFO] --- db-migrator-maven-plugin:2.5-j8:migrate (dev_migrations) @ xjobs-server ---
[INFO] Sourcing database configuration from file: /srv/apps/xjobs-server/src/main/resources/database.properties
[INFO] Environment: development
[INFO] Migrating jdbc:postgresql://localhost:5432/xjobs_deve using migrations at /srv/apps/xjobs-server/src/migrations/
[INFO] Creating schema version table for POSTGRESQL DB
[INFO] Executing: create table schema_version (version varchar(32) not null unique, applied_on timestamp not null, duration int not null)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  0.864 s
[INFO] Finished at: 2021-07-26T00:42:50+08:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.javalite:db-migrator-maven-plugin:2.5-j8:migrate (dev_migrations) on project xjobs-server: Execution dev_migrations of goal org.javalite:db-migrator-maven-plugin:2.5-j8:migrate failed: org.javalite.activejdbc.DBException: org.postgresql.util.PSQLException: ERROR: relation "schema_version" already exists, query: create table schema_version (version varchar(32) not null unique, applied_on timestamp not null, duration int not null) -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutionException

And the javalite version和 javalite 版本

<javalite.version>2.5-j8</javalite.version>

I have checked schema_version table, it does exist, and it contains all migration sequence numbers.我检查了schema_version表,它确实存在,并且包含所有迁移序列号。 I don't understand why the migrator still needs to create the table again.我不明白为什么迁移者仍然需要再次创建表。

-- UPDATE - 更新

some config in pom.xml pom.xml一些配置

    <properties>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
        <javalite.version>2.5-j8</javalite.version>
        <jetty.version>9.4.24.v20191120</jetty.version>
        <environments>development</environments>
    </properties>
    ...
    <plugin>
        <groupId>org.javalite</groupId>
        <artifactId>db-migrator-maven-plugin</artifactId>
        <version>${javalite.version}</version>
        <dependencies>
        <dependency>
                    <groupId>org.postgresql</groupId>
                    <artifactId>postgresql</artifactId>
                    <version>42.2.18</version>
                </dependency>
        </dependencies>
        <configuration>
            <configFile>${project.basedir}/src/main/resources/database.properties</configFile>
            <environments>${environments}</environments>
        </configuration>
        <executions>
            <execution>
                <id>dev_migrations</id>
                <phase>validate</phase>
                <goals>
                    <goal>migrate</goal>
                </goals>
            </execution>
        </executions>
    </plugin>

I created an example to test exactly the scenario you have.我创建了一个示例来准确测试您拥有的场景。 Fortunately, the JavaLite Migrator is working as expected.幸运的是,JavaLite Migrator 正在按预期工作。

Here is the link to the example: https://github.com/javalite/javalite-examples/tree/master/postgresql-example这是示例的链接: https : //github.com/javalite/javalite-examples/tree/master/postgresql-example

No matter how many times you run the migrator, it works as expected every time:无论您运行迁移器多少次,它每次都按预期工作:

[INFO] --- db-migrator-maven-plugin:2.5-j8:migrate (dev_migrations) @ postgresql-example ---
[INFO] Sourcing database configuration from file: /home/igor/projects/javalite/javalite-examples/postgresql-example/src/main/resources/database.properties
[INFO] Environment: development.test
[INFO] Migrating jdbc:postgresql://localhost/postgres using migrations at /home/igor/projects/javalite/javalite-examples/postgresql-example/src/migrations/
[INFO] Trying migrations at: /home/igor/projects/javalite/javalite-examples/postgresql-example/src/migrations 
[INFO] No new migrations are found
[INFO] Environment: development
[INFO] Migrating jdbc:postgresql://localhost/postgres using migrations at /home/igor/projects/javalite/javalite-examples/postgresql-example/src/migrations/
[INFO] Trying migrations at: /home/igor/projects/javalite/javalite-examples/postgresql-example/src/migrations 
[INFO] No new migrations are found
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  0.460 s
[INFO] Finished at: 2021-07-26T12:39:06-05:00

So, why are you having an issue?那么,你为什么有问题? It is possible that you have multiple schemas in the database, and improperly configured visibility, such that under one condition, you see the schema_version table and under another, you do not.您可能在数据库中有多个模式,并且可见性配置不正确,因此在一种情况下,您会看到schema_version表,而在另一种情况下则看不到。 There have been reported similar cases before for Oracle, and the fix was related to eliminating leaking table visibility under different users. Oracle 之前也有过类似案例的报道,该修复与消除不同用户下的泄漏表可见性有关。 This is where you need to focus to fix the issue.这是您需要集中精力解决问题的地方。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM