在Heroku上,运行db:migrate而没有错误,填充了`schema_migrations`,但架构没有更改

时间:2013-09-02 20:22:13

标签: activerecord heroku sinatra rake heroku-postgres

我有一个Sinatra应用程序,我正在尝试使用Heroku进行部署。该应用程序正在运行,并且工作正常(不依赖于数据库连接的部分)。

我有一个为应用程序创建的Postgresql数据库,但出于某种原因,当我尝试迁移数据库时(我的初始迁移是创建一些表),虽然没有错误,但是没有创建表。更奇怪的是,schema_migrations表中填充了迁移的时间戳,就好像它们运行正确一样。

我尝试重新启动应用,以及删除数据库并创建新数据库。

感谢您的帮助。

请参阅下面的输出。应该有13次迁移。

dave@macbook:~/Development/personal/sinatra-app$ heroku pg:reset DATABASE_URL

 !    WARNING: Destructive Action
 !    This command will affect the app: sinatra-app-api
 !    To proceed, type "sinatra-app-api" or re-run this command with --confirm sinatra-app-api

> sinatra-app-api
Resetting HEROKU_POSTGRESQL_BROWN_URL (DATABASE_URL)... done

dave@macbook:~/Development/personal/sinatra-app$ heroku config
=== sinatra-app-api Config Vars
DATABASE_URL:                postgres://OWNER:PASSWORD@HOST:5432/sinatra-app-database
HEROKU_POSTGRESQL_BROWN_URL: postgres://OWNER:PASSWORD@HOST:5432/sinatra-app-database

dave@macbook:~/Development/personal/sinatra-app$ heroku pg:psql
psql (9.2.4)
sinatra-app-database=> \dt
No relations found.

dave@macbook:~/Development/personal/sinatra-app$ heroku run rake db:migrate --trace
Running `rake db:migrate --trace` attached to terminal... up, run.1128
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
{"production"=>{"adapter"=>"postgresql", "database"=>"sinatra-app-database", "username"=>"OWNER", "password"=>"PASSWORD", "host"=>"HOST", "port"=>5432}}
** Execute db:migrate
dave@macbook:~/Development/personal/sinatra-app$ heroku pg:psql
psql (9.2.4)

sinatra-app-database=> \dt
                  List of relations
 Schema |       Name        | Type  |     Owner
--------+-------------------+-------+----------------
 public | schema_migrations | table | OWNER
(1 row)

sinatra-app-database=> select * from schema_migrations ;
    version
----------------
 20131364733212
 20131364737284
 20131364755591
 20131364755887
 20131364756006
 20131364766771
 20131365332699
 20131365332706
 20131365333238
 20131365334088
 20131365334094
 20131376235209
 20131378061826
(13 rows)

另请参阅我的Rakefile的相关部分:

# encoding: utf-8
#!/usr/bin/env rake
require "rubygems"
require "active_record"
require "active_support/inflector"
require "logger"
require "yaml"
require 'csv'
require 'bundler'
require 'rake/testtask'
require 'erb'

desc "Used internally by the Rakefile."
task "environment" do
   environment = ENV["RACK_ENV"] || "development"
   configuration = YAML.load(ERB.new(File.read(File.join("config","database.yml"))).result)
   ActiveRecord::Base.establish_connection(configuration[environment])
end

namespace :db do
   desc "Run database migrations."
   task :migrate => :environment do
      ActiveRecord::Migrator.migrate('db/migrate', ENV["VERSION"] ? ENV["VERSION"].to_i : nil )
   end

   desc "Rollback last <STEPS> migrations. Defaults to 1"
   task :rollback => :environment do
      ActiveRecord::Migrator.rollback('db/migrate', ENV["STEPS"] ? ENV["STEPS"].to_i : 1)
   end

    desc "Forwards next <STEPS> migrations. Defaults to 1"
    task :forward => :environment do
      ActiveRecord::Migrator.forward('db/migrate', ENV["STEPS"] ? ENV["STEPS"].to_i : 1)
    end
end

0 个答案:

没有答案