2

There is a small project of mine reaching its release, based on squeryl - typesafe relational database framework for Scala (JVM based language).

I foresee multiple updates after initial deployment. The data entered in the database should be persisted over them. This is impossible without some kind of data migration procedure, upgrading data for newer DB schema. Using old data for testing new code also requires compatibility patches.

Now I use automatic schema generation by framework. It seem to be only able create schema from scratch - no data persists.

Are there methods that allow easy and formalized migration of data to changed schema without completely dropping automatic schema generation?

So far I can only see an easy way to add columns: we dump old data, provide default values for new columns, reset schema and restore old data.

How do I delete, rename, change column types or semantics?

If schema generation is not useful for production database migration, what are standard procedures to follow for conventional manual/scripted redeployment?

Basilevs
  • 22,440
  • 15
  • 57
  • 102

1 Answers1

1

There have been several discussions about this on the Squeryl list. The consensus tends to be that there is no real best practice that works for everyone. Having an automated process to update your schema based on your model is brittle (can't handle situations like column renames) and can be dangerous in production. Personally, I like the idea of "migrations" where all of your schema changes are written as SQL. There are a few frameworks that help with this and you can find some of them here. Personally, I just use a light wrapper around the psql command line utility to do schema migrations and data loading as it's a lot faster for the latter than feeding in the data over JDBC.

Dave Whittaker
  • 3,102
  • 13
  • 14