EzDevInfo.com

migration interview questions

Top migration frequently asked interview questions

Rails migration for change column

We have script/generate migration add_fieldname_to_tablename fieldname:datatype syntax for adding new columns to a model.

On the same line, do we have a script/generate for changing the datatype of a column? Or should I write SQL directly into my vanilla migration?

I want to change a column from datetime to date.


Source: (StackOverflow)

Migrating from JSF 1.2 to JSF 2.0

I am working with a rather large app written in JSF 1.2. JSF 1.2 is around 6 years old now. I need to upgrade to JSF 2.0. How painful will this be? I noticed that some attributes in custom tags have been changed etc.


Source: (StackOverflow)

Advertisements

rake db:schema:load vs. migrations

Very simple question here - if migrations can get slow and cumbersome as an app gets more complex and if we have the much cleaner rake db:schema:load to call instead, why do migrations exist at all?

If the answer to the above is that migrations are used for version control (a stepwise record of changes to the database), then as an app gets more complex and rake db:schema:load is used more instead, do they continue to maintain their primary function?


Caution:

From the answers to this question: rake db:schema:load will delete data on a production server so be careful when using it.


Source: (StackOverflow)

Rails migration for has_and_belongs_to_many join table

How do I do a script/generate migration to create a join table for a has_and_belongs_to_many relationship?

The application runs on Rails 2.3.2, but I also have Rails 3.0.3 installed.


Source: (StackOverflow)

Backwards migration with Django South

Ok, so this seems like a really silly thing to ask, and I'm sure I'm missing something somewhere.

How do you perform a backwards migration using South on Django?

So I've tweaked my models, created a migration with schemamigration, run the migration with migrate, and now I realise that's not quite what I wanted and I want it back the way before.

Short of manually editing db tables and removing migration files, how should I go about rolling the migration back? I find references to backward migrations using South via Google, but have yet to find a solid code example for it.

Can anyone help?


Source: (StackOverflow)

How to handle too long index names in a Rails migration with MySQL?

I am trying to add an unique index that gets created from the foreign keys of 4 associated tables (users, universities, subject_names, subject_types).

add_index :studies, ["user_id", "university_id", \
          "subject_name_id", "subject_type_id"], 
          :unique => true

MySQL's limitation for the index name causes the migration to stop. Here is the error message.

Index name 'index_studies_on_user_id_and_university_id_and_subject_\
           name_id_and_subject_type_id' on table 'studies' is too long; \
           the limit is 64 characters

How can I handle this? Can I use an alias?


Source: (StackOverflow)

Mechanisms for tracking DB schema changes [closed]

What are the best methods for tracking and/or automating DB schema changes? Our team uses Subversion for version control and we've been able to automate some of our tasks this way (pushing builds up to a staging server, deploying tested code to a production server) but we're still doing database updates manually. I would like to find or create a solution that allows us to work efficiently across servers with different environments while continuing to use Subversion as a backend through which code and DB updates are pushed around to various servers.

Many popular software packages include auto-update scripts which detect DB version and apply the necessary changes. Is this the best way to do this even on a larger scale (across multiple projects and sometimes multiple environments and languages)? If so, is there any existing code out there that simplifies the process or is it best just to roll our own solution? Has anyone implemented something similar before and integrated it into Subversion post-commit hooks, or is this a bad idea?

While a solution that supports multiple platforms would be preferable, we definitely need to support the Linux/Apache/MySQL/PHP stack as the majority of our work is on that platform.


Source: (StackOverflow)

How can I rename a database column in a Rails migration?

I wrongly named a column hased_password instead of hashed_password.

How can update database scheme with using migration to rename this column?


Source: (StackOverflow)

Rails DB Migration - How To Drop a Table?

I added a table that I thought I was going to need, but now no longer plan on using it. How should I remove that table?

I've already ran migrations, so the table is in my database. I figure rails generate migration should be able to handle this, but I haven't figured out how yet.

I've tried rails generate migration drop_tablename, but that just generated an empty migration.

What is the "official" way to drop a table in Rails?


Source: (StackOverflow)

Version of SQLite used in Android?

What is the version of SQLite used in Android?

Reason: I'm wondering how to handle schema migrations. The newer SQLite versions support an "ALTER TABLE" SQL command which would save me having to copy data, drop the table, recreate table and re-insert data.


Source: (StackOverflow)

How do you write a migration to rename an ActiveRecord model and its table in Rails?

I'm terrible at naming and realize that there are a better set of names for my models in my Rails app. Is there a way to use a migration to rename a model and its table?


Source: (StackOverflow)

How do I migrate a model out of one django app and into a new one?

I have a django app with four models in it. I realize now that one of these models should be in a separate app. I do have south installed for migrations, but I don't think this is something it can handle automatically. How can I migrate one of the models out of the old app into a new one?

Also, keep in mind that I'm going to need this to be a repeatable process, so that I can migrate the production system and such.


Source: (StackOverflow)

How to migrate/convert from SVN to Mercurial (hg) on windows

I'm looking for a tool to migrate a couple of SVN repositories to Mercurial, with history, labels and so on.

I'm using TortoiseHg (Windows x32), so ConvertExtensions are discarded. There's some info on how to do this process on a Linux box (hgsvn), but I don't have a Linux machine available.

Can I use those Python scripts on Windows? If so, what do I need to do it? Or, what other tools can I use to do this process?

Basically, how can I convert an SVN project to Mercurial?


Source: (StackOverflow)

Add a default value to a column through a migration

How do I add a default value to a column that already exists through a migration?

All the documentation I can find shows you how to do it if the column doesn't already exist but in this case it does.


Source: (StackOverflow)

Maven is not working in Java 8 when JavaDoc tags are incomplete

Since I use Maven I have been able to build and install in my local repository projects that have incomplete java doc tags (for example, a missing parameter).

However, since I migrated to Java 8 (1.8.0-ea-b90) Maven is absolutely strict about missing documentation tags and show me lots of JavaDoc errors related to JavaDoc problems when I try to build or install a project where the JavaDoc is not "perfect". Some of the projects I am trying to compile and install in my local repository are third party projects from which I do not have control. So the workaround of just fixing all the javadocs in all these projects does not seem to be feasable in my scenario.

This is a small part of the output I see when I execute mvn clean package install in my project:

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 9.026s
[INFO] Finished at: Mon Apr 08 21:06:17 CEST 2013
[INFO] Final Memory: 27M/437M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-javadoc-plugin:2.9:jar (attach-javadocs) on project jpc: MavenReportException: Error while creating archive:
[ERROR] Exit code: 1 - /Users/sergioc/Documents/workspaces/heal/jpc/src/main/java/org/jpc/engine/prolog/PrologDatabase.java:10: error: @param name not found
[ERROR] * @param terms the terms to assert
[ERROR] ^
[ERROR] /Users/sergioc/Documents/workspaces/heal/jpc/src/main/java/org/jpc/engine/prolog/PrologDatabase.java:11: warning: no description for @return
[ERROR] * @return
[ERROR] ^

The JavaDoc plugin is configured like this in my POM:

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-javadoc-plugin</artifactId>
        <version>2.9</version>
        <executions>
            <execution>
                <id>attach-javadocs</id>
                <goals>
                    <goal>jar</goal>
                </goals>
            </execution>
        </executions>
    </plugin>

As I said before, everything is working fine if I go back to Java 7. Maybe is this a bug related to Maven running in Java 8 ? How could I make it work (i.e., being able to build the Javadoc of the project and install its code in my local repository) with Java 8 ? I have tested with both Maven 3.0.3 and 3.0.5 in OSX.

UPDATE:

If I change my JavaDoc plugin configuration with <failOnError>false</failOnError> (thanks Martin):

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-javadoc-plugin</artifactId>
        <version>2.9</version>
        <executions>
            <execution>
                <id>attach-javadocs</id>
                <goals>
                    <goal>jar</goal>
                </goals>
            </execution>
        </executions>
    </plugin>

Then the project is installed in my local repository. However, the javadoc jar is still not generated:

A fragment of the output I see in the console with this new configuration is:

[ERROR] MavenReportException: Error while creating archive: Exit code: 1 - /Users/....java:18: warning: no @param ... Command line was: /Library/Java/Home/bin/javadoc @options @packages

Refer to the generated Javadoc files in '/Users/sergioc/Documents/workspaces/heal/minitoolbox/target/apidocs' dir.

at org.apache.maven.plugin.javadoc.AbstractJavadocMojo.executeJavadocCommandLine(AbstractJavadocMojo.java:5043) at org.apache.maven.plugin.javadoc.AbstractJavadocMojo.executeReport(AbstractJavadocMojo.java:1990) at org.apache.maven.plugin.javadoc.JavadocJar.execute(JavadocJar.java:181) at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101) at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209) at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153) at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59) at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183) at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161) at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320) at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156) at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537) at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196) at org.apache.maven.cli.MavenCli.main(MavenCli.java:141) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:491) at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290) at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230) at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409) at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)

Any workaround about how to build the sources, install the project and generate the Java doc jar in one step as it was working with Java 7 ?


Source: (StackOverflow)