Questions tagged [dbmigrate]

Database migration framework.

What question should have this tag?

Database migration related question using a framework.

Basic Definitions

Database migration refers to the change of schema over time. It is common for a project's schemas to evolve depends on the need. Similarly, migration can help to add or remove columns from the schema/table.

Introduction

Typically a migration has an up and down method, so you can roll back any migrations. For example in nodejs, a migration might look like this:

//20180722013000-location.ts

exports.up = (db: any) => {
    return db.createTable("Location", {
        description: "text",
        geoCode: "jsonb",
        id: {
            allowNull: false,
            autoIncrement: true,
            primaryKey: true,
            type: "int",
        },
        locationId: "int",
        name: "string",
        open: "boolean",
    });
};

exports.down = (db: any) => {
    return db.dropTable("Location");
};

This migration will handle creating a table with that scheme on up and dropTable on down.

Learn more

Rails Active Record migration

Node Migration

Sequelize cli // A simple solution for migration and even support seeding

290 questions
229
votes
6 answers

How to rollback just one step using rake db:migrate

After adding migration files in the db/migrate folder and running rake db:migrate, I want get back to the previous step, I think using VERSION=n is the right way to do that, but I don't know the correct value of n to use. Is there any command to…
mko
  • 21,334
  • 49
  • 130
  • 191
32
votes
2 answers

How can I tell what changes 'rake db:migrate' will apply before applying them?

The command rake db:migrate will apply all relevant new migrations to a database and will list in the output the migrations that were applied. I'd like to know in advance what migrations will be applied so as to note down a list of the changes that…
Jon Cram
  • 16,609
  • 24
  • 76
  • 107
25
votes
14 answers

Getting: "Migrations are pending; run 'bin/rake db:migrate RAILS_ENV=development' to resolve this issue." after cloning and migrating the project

I cloned my project. Bundled with "bundle install", then run "rake db:migrate". I am getting this error: (when I run the rails server and open my browser to localhost:3000) "Migrations are pending; run 'bin/rake db:migrate RAILS_ENV=development' to…
user2911232
24
votes
5 answers

PRIMARY KEY issue with creating tables in Rails using rake db:migrate command with mysql

My version of rails is 4.0.0, my version of mysql is Ver 14.14 Distrib 5.7.9, for Win64 (x86_64). I am operating of an older version of rails as I was getting some clashes with the mysql as per my previous question Here. (check Kalelc's approved…
Aerosewall1
  • 351
  • 1
  • 2
  • 8
24
votes
7 answers

Rails: I update migration file then run db:migrate, but my schema isn't updating

I'm trying to add an extra field to one of my tables. I've added the field in the migration file (under db\migrate), then ran 'rake db:migrate' which ran without troubles. My text editor even told me my schema.db file has been updated and needs to…
Evolve
  • 8,939
  • 12
  • 51
  • 63
22
votes
3 answers

Can't migrate database after scaffold. Section 2.2 Ruby on Rails Tutorial Michael Hartl

I'm working through the Hartl ruby on rails tutorial (section 2.2), and I'm having trouble migrating the database. Everything seemed to be working, and then I ran rails generate scaffold User name:string email:string Afterwards I tried to run…
Hopscott
  • 251
  • 2
  • 6
12
votes
1 answer

'Stuff' And 'FOR XML PATH' alternative in Mysql for the following stored prodedure of Ms-sql

I have the following query in Ms-Sql INSERT INTO tbl_web_price_update Select bd_book_code, Case When pd.bpd_price is null then cast((a.bd_price*c.ptm_price) as numeric(10)) else …
Ratna
  • 2,289
  • 3
  • 26
  • 50
11
votes
2 answers

Heroku rake db:migrate results in Error R13 (Attach error) -> Failed to attach to process

I have a rails app on heroku that i am unable to run my latest database changes with. Running heroku run rake db:migrate gives me Running `rake db:migrate` attached to terminal... up, run.3167 ! Heroku client internal error. ! Search for help…
user922592
10
votes
1 answer

NodeJS db-migrate TypeError: Cannot read property '1' of null

I've just installed the nodejs package db-migrate into an existing nodejs project. Everything seems to be configured correctly in regards to the connection to the DB. Database.json: { "development": "postgres://blabla", "production":…
cavpollo
  • 4,071
  • 2
  • 40
  • 64
10
votes
2 answers

Rails: differences in db/schema.rb - null: false at created_at/updated_at columns

Does anybody know why whenever I run rake db:migrate in my production environment, the schema.rb file is changed? The differences are only on the created_at, update_at columns of all model tables: - t.datetime "created_at" - t.datetime…
Lazarus Lazaridis
  • 5,803
  • 2
  • 21
  • 35
10
votes
2 answers

How to make rake db:migrate generate schema.rb when using :sql schema format

If using the this option in config/application.rb: config.active_record.schema_format = :sql then when you do: rake db:migrate it only dumps the db/structure.sql. I know it isn't using the db/schema.rb since it is using the :sql option, but how…
Gary S. Weaver
  • 7,966
  • 4
  • 37
  • 61
9
votes
4 answers

db:migrate hangs on simple migration

I am using PostgreSQL, Rails 3.1.3 and Ruby 1.9.3. I am struggling to use db:migrate as outlined here. This is what I am seeing in the terminal: funkdified@funkdified-laptop:~/railsprojects/hartl$ bundle exec rake db:migrate --trace ** Invoke…
Abram
  • 39,950
  • 26
  • 134
  • 184
9
votes
2 answers

How to import from sql dump to MongoDB?

I am trying to import data from MySQL dump .sql file to get imported into MongoDB. But I could not see any mechanism for RDBMS to NoSQL data migration. I have tried to convert the data into JSON and CSV but it is not giving m the desired output in…
Jaffer Wilson
  • 7,029
  • 10
  • 62
  • 139
9
votes
3 answers

DEPRECATION WARNING: You have Rails 2.3-style plugins in vendor/plugins! Support will be removed in Rails 4.0

Possible Duplicate: Rails 2.3-style plugins and deprecation warnings running task in Heroku I am running rake db:migrate gives me the following warnings and then aborts: $ heroku rake db:migration --trace DEPRECATION WARNING: You have Rails…
Hesham
  • 525
  • 1
  • 5
  • 11
8
votes
2 answers

Why database migration fails in case of blob datatype in Rails?

I'm trying to create a simple application with Ruby on Rails. I've created this scaffold: rails generate scaffold Pic title:string content:blob description:text and when I try to migrate db with rake db:migrate I'm getting this error: rake…
shift66
  • 11,760
  • 13
  • 50
  • 83
1
2 3
19 20