Rails 5 rake db:schema:load不会在postgres数据库上创建表或运行initialize_schema_migrations_table()

时间:2018-04-03 22:49:48

标签: ruby-on-rails postgresql docker-compose rake travis-ci

我目前正在尝试在Travis CI上设置我的Rails 5.1.6系统测试(使用ruby 2.3.7)。在我的travis CI测试中,我使用docker-compose将我的应用程序连接到postgres数据库。在我的每次系统测试之前,我正在运行

rake db:schema:load --trace

将数据库清除为干净状态。这在我的系统测试中本地工作正常(使用我的开发机器中的postgreSQL)。但是,当我使用postgres容器运行docker-compose进行系统测试时,我的rake db:schema:load --trace输出没有调用所有的create table命令,因此没有按预期清除我的数据库。这是输出:

** Invoke db:schema:load (first_time)
** Invoke environment (first_time)
** Execute environment
** Invoke db:load_config (first_time)
** Execute db:load_config
** Invoke db:check_protected_environments (first_time)
** Invoke environment 
** Invoke db:load_config 
** Execute db:check_protected_environments
   (0.6ms)  SELECT "schema_migrations"."version" FROM     "schema_migrations" ORDER BY "schema_migrations"."version" ASC
       (0.4ms)  SELECT "ar_internal_metadata"."value" FROM     "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1  [["key",     "environment"]]
       (0.3ms)  SELECT "schema_migrations"."version" FROM     "schema_migrations" ORDER BY "schema_migrations"."version" ASC
   (0.3ms)  SELECT "ar_internal_metadata"."value" FROM     "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1  [["key",     "environment"]]
       (0.3ms)  SELECT "schema_migrations"."version" FROM     "schema_migrations" ORDER BY "schema_migrations"."version" ASC
       (0.3ms)  SELECT "ar_internal_metadata"."value" FROM     "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1  [["key",     "environment"]]
** Execute db:schema:load
[4ed5f501-7177-49e5-973e-f49e0d91ff89] Started GET "/" for 127.0.0.1 at 2018-04-03 22:28:21 +0000

我希望它看起来像这样:

** Invoke db:schema:load (first_time)
** Invoke environment (first_time)
** Execute environment
** Invoke db:load_config (first_time)
** Execute db:load_config
** Invoke db:check_protected_environments (first_time)
** Invoke environment 
** Invoke db:load_config 
** Execute db:check_protected_environments
   (0.5ms)  SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
   (0.3ms)  SELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1  [["key", "environment"]]
   (0.1ms)  SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
   (0.1ms)  SELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1  [["key", "environment"]]
   (0.1ms)  SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
   (0.1ms)  SELECT "ar_internal_metadata"."value" FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1  [["key", "environment"]]
** Execute db:schema:load
-- enable_extension("plpgsql")
  SQL (0.3ms)  CREATE EXTENSION IF NOT EXISTS "plpgsql"
   -> 0.0123s
-- create_table("builds", {:id=>:serial, :force=>:cascade})

后跟其余的create_table命令,直到设置了数据库模式。

这是我的docker-compose.yml

version: '3'
services:
  postgres:
    image: postgres:9.5.3
    volumes:
      - data:/var/lib/postgresql/data
  app:
    image: $DOCKER_USERNAME/vizzy:$TRAVIS_COMMIT
    build:
      context: .
      args:
        RAILS_MASTER_KEY: $RAILS_MASTER_KEY
    command: bundle exec rails s -p 3000 -b '0.0.0.0'
    environment:
      - RAILS_MASTER_KEY=$RAILS_MASTER_KEY
      - POSTGRES_USER=postgres
      - RAILS_ENV=ci_test
      - HEADLESS=yes
    volumes:
      - .:/app
    ports:
      - 3000:3000
    depends_on:
      - postgres
volumes:
  data:
    external: true

非常感谢任何帮助。奇怪的是我的系统测试如何在本地传递,但没有使用docker-compose

运行

0 个答案:

没有答案