database-migration

We have lots of database migration files - should we keep them?

佐手、 提交于 2019-12-04 19:14:11
问题 We have around 100 database migration files. Many of them make schema changes which are irreversible. There are also later migrations which change or remove tables which were created in earlier migrations. We are creating new databases straight from the schema.rb file, so we were wondering if there is any reason to keep the full set of migrations? We would create a new migration which is based on our existing schema.rb. 回答1: Yes, what you're proposing is considered a best practice. I've done

How to gracefully handle “Mysql2::Error: Invalid date” in ActiveRecord?

﹥>﹥吖頭↗ 提交于 2019-12-04 17:30:01
I'm building a Rails 3.2 app upon a legacy database which also has some broken records in different tables. One of the issues giving the most headache is that it includes invalid dates. I've setup a sandbox which I manually fixed one time to get my code working. Now it's time for deployment. For this reason, the sandbox is reset every night and copied from the live database, ferret indexes are rebuilt, and migrations are re-applied. We are going to deploy to the sandbox often to get in the last fixes before deploying to the live setup. As the legacy PHP app and this new Rails app need to run

Laravel's Artisan says nothing to migrate

馋奶兔 提交于 2019-12-04 15:13:12
问题 I installed migrations with php artisan migrate:install then created a migration with the php artisan migrate:make create_teams_table command. Now I try to run them with the following command that I made according to the official documentation: php artisan migrate --path=app/foo/migrations/2014_01_21_143531_create_teams_table.php This gives me the following on the console: Nothing to migrate. The migrations table in the database is empty and the new table isn't created neither. I don't

Purpose and semantic of IMigrationMetadata interface in Entity Framework

大兔子大兔子 提交于 2019-12-04 12:25:55
问题 I'm trying to find out what is the semantic of System.Data.Entity.Migrations.Infrastructure.IMigrationMetadata interface in the EF. I know that it's used to manage and apply DB migrations. But I can't find detailed information about it. To be specific I would like to know: What Source property is used for? Why it's always null when I generate migrations using tools? What Target property is used for? I see that tools is generating something Base64-looking and placed into resources. What is it?

How to change primary key in rails migration file?

核能气质少年 提交于 2019-12-04 11:50:40
问题 I need to migrate an old mysql table like this: Products name (string, primary_key) to this schema: Products id (integer, primary_key, auto_generated) name (unique) I need the Products.id values populated in the new table. How can i write the rails migration file? I am using Rails 3.2.7 I have 2 problems now: 1. I can't find a method to remove primary key in ActiveRecord::Migration 2. I don't know how to generate values for newly added primary key. 回答1: You could execute arbitrary SQL in your

Could not find driver while migrating on Laravel 4 using XAMPP Server Linux (Ubuntu)

两盒软妹~` 提交于 2019-12-04 11:40:52
I have installed Laravel 4.1 everything worked just fine, but when I try to use migration it throws a PDO Exception saying: [PDOException] could not find driver I found many answers on StackOverFlow, but none of them solved my problem, unfortunately. I have tried to enable pdo extension and pdo_mysql extension, but it says that pdo is already loaded. I have tried to reinstall PDO and PDO MySQL but nothing worked. I am using XAMPP Server on a Ubuntu 64bit machine. Thank you in advance. If you are looking for simple solution, I had same issue & this worked for me.. When you run php artisan from

There is already an object named '__MigrationHistory' in the database

廉价感情. 提交于 2019-12-04 10:50:46
When I tried to execute SQLQuery (generated by Update-Database -Verbose -f -Script locally in Visual Studio) on remote database, I saw the following error returned by SQL Server Management Studio: Msg 2714, Level 16, State 6, Line 1 There is already an object named '__MigrationHistory' in the database. How to solve this? __MigrationHistory is an auto-generated table used by EF to track what upgrades/patches it has applied to the database. EF is completely aware of that table and handles it on its own. You should ot create/drop/alter that table. It seems your database already has that table. If

Rails Migration: Remove constraint

萝らか妹 提交于 2019-12-04 07:46:24
问题 I have a table in a Rails application which (in schema.rb) looks like: create_table "users", :force => true do |t| t.string "name", :null=>false t.string "address", :null=>false end I would like to write a rails migration to allow nulls for the address field. i.e. after the migration the table looks like this: create_table "users", :force => true do |t| t.string "name", :null=>false t.string "address" end What do I need to do to remove the constraint? 回答1: Not sure you can call t.address ?

How do I modify a column using Grails' database migration plugin's Groovy DSL?

半城伤御伤魂 提交于 2019-12-04 07:08:54
Can you give me an example of a groovy changeset using the modifyDataType method? I tried this: databaseChangeLog = { changeSet(author: "user", id: "5-1") { modifyDataType(tableName: "test", columnName: "description4", newDataType: "int(11)") } } But modifyDataType is not recognized. I also tried modifyColumn , but I get the same result. The underlying question is: What kind of tags does the dsl support, and how are they used? All Liquibase refactorings should work - the Groovy DSL mirrors the Liquibase XML. I didn't have a test for modifyDataType but added it to my test script and it worked

Can we define a GROUP_CONCAT function in PostgreSQL?

本小妞迷上赌 提交于 2019-12-04 07:08:30
问题 I have several lines of SQL code for my legacy database with GROUP_CONCAT statements, as in: SELECT SUM(age), GROUP_CONCAT(sal) FROM Users; In PostgreSQL, I can do the same with: SELECT SUM(age), string_agg(sal, ', ') FROM Users; I would like to reuse the old SQL as much as possible. So I need to define a GROUP_CONCAT function that internally calls string_agg . Is this possible? EDIT: The linked question is unrelated! My question asks "How to define a function called group_concat?". The