Cloud Foundry: Design and Architecture
Derek Collison discusses the goals, the design premises and patterns employed in creating the architecture of Cloud Foundry, VMware’s open source PaaS, unveiling internal architectural details.
The content has been bookmarked!
There was an error bookmarking this content! Please retry.
Posted by Robert Bazinet on Oct 04, 2007
Rob Conery from the SubSonic project recently introduced migrations, which allow .NET developers to create database schema using code.
In case you have not heard of the SubSonic project its worth taking a look. It provides the .NET developer with a set of tools which create your Data Access Layer (DAL) for you, either at run time or from a set of generated classes. The project was inspired from Ruby on Rails and provides Active Record support, scaffolding, ORM and now Migrations.
From Rob's blog, migrations are:
For those who don’t know, Migrations allow you to build out your DB schema using code. It’s a Rails Thing, and if you’re not familiar with them you can watch one of my webcasts where I use them (right around the 3 minute mark), or just read up on them here.
The concept is that you version the building of your DB into code files, called “Migrations”. Using code, you can build and change your DB as needed, and keep a reference of this in your app’s codebase. Since you’re using code to build out the schema, you can do all kinds of neat things like add data, ping services, send emails, etc whenever you change around the schema. This puts the DB work into your app and out of the designer, which in some cases can be neat.
Rob gives a nice example of what creating a migration looks like in C# code:
Currently, all migrations are built off of an abstract base class called, as you might guess, SubSonic.Migration. Each migration must inherit from this base class, and must also implement two methods: Up (versions your DB upward) and Down(versions it down). Here’s an example:
public class Migration001:Migration {
public override void Up() {
TableSchema.TableCollection tables = new TableSchema.TableCollection();
TableSchema.Table t = new TableSchema.Table(“Test1″);
t.AddColumn(“Name”, System.Data.DbType.String);
t.AddColumn(“Description”, System.Data.DbType.String,5000);
t.AddColumn(“DateEntered”, System.Data.DbType.DateTime,0, false, “getdate()”);
AddSubSonicStateColumns(t);
tables.Add(t);
t = new TableSchema.Table(“Test2″);
t.AddColumn(“Name”, System.Data.DbType.String);
t.AddColumn(“Friend”, System.Data.DbType.String);
t.AddColumn(“FriendInt”, System.Data.DbType.Int32, 0,false,“50″);
AddSubSonicStateColumns(t);
tables.Add(t);
Create(tables);
}
public override void Down() {
Drop(new string[] { “Test1″, “Test2″ });
}
}
As the developer's schema changes over time and columns need to be added, changed or removed. SubSonic's Migrations support this as well:
You can also add/remove columns, and alter their settings (without dropping and losing data). This next bit of code shows not only how to alter data, but also why you’d use migrations in the first place - it’s a road map of how your DB has changed over time:
public class Migration002:Migration {
public override void Up() {
//alter the description field - change to 1200
TableSchema.TableColumn col = DataService.GetSchema(“Test1″, “Northwind”).GetColumn(“Description”);
col.MaxLength = 1200;
//use AlterColumn to run an Alter statement - we don’t want to save the schema
//since that would overwrite what we’re trying to do
AlterColumn(col);
//add a new column to Products
DataService.GetSchema(“Products”, “Northwind”).AddColumn(“MyNewColumn”,System.Data.DbType.DateTime);
//add another one and set the default, as well as non-nullable
DataService.GetSchema(“Products”, “Northwind”).AddColumn(“MaxInventory”, System.Data.DbType.Int32,0,false,“100″);
}
public override void Down() {
//the Down() method reverses what Up() did
//reset Description to 9000
TableSchema.TableColumn col = DataService.GetSchema(“Test1″, “Northwind”).GetColumn(“Description”);
col.MaxLength = 9000;
AlterColumn(col);
//remove MyNewColumn and MaxInventory
RemoveColumn(“Northwind”, “Products”, “MyNewColumn”);
RemoveColumn(“Northwind”, “Products”, “MaxInventory”);
}
}
Anyone familiar with Ruby on Rails migrations you know a table call schema_info which keeps track of which migrations have been applied. SubSonic handles versioning much the same way, storing schema version information in a table called Subsonic_Schema. Migrations are run with simple commands from the command line.
Creating a migration:
sonic.exe migration /create
Running a migration:
sonic.exe migrate
The SubSonic project bring much of what Ruby on Rails developers like to .NET. It is well worth checking the project out. SubSonic supports more databases than Microsoft SQL Server, feel free to use Oracle or MySQL too.
Troubleshoot Java/.NET performance while getting full visibility in production
Visual Studio vNext: ALM features for Agile Planning, Team Collaboration
Automating Error Reporting for .NET Applications
RDBMS to NoSQL: Managing the Transition
The WebSphere Liberty Profile for Developers: An Introduction
Derek Collison discusses the goals, the design premises and patterns employed in creating the architecture of Cloud Foundry, VMware’s open source PaaS, unveiling internal architectural details.
Andrew Watson talks about the work of the OMG, where CORBA is alive and well (hint: in your car), UML and UML Profiles vs. custom Modeling languages, DDS and other middleware, and much more.
Sohil Shah discusses creating iPhone and Android enterprise mobile applications based on cloud services using the open source platform OpenMobster.
Paul Sanford presents the transformations supported by data throughout its life cycle, and how that can be better done with Splunk, an engine for monitoring and analyzing machine-generated data.
A common “best practice” for unit tests is to only write a one assertion in each test. I intend to question this advice by showing that multiple assertions per test are both necessary and beneficial.
John Rauser presents the architectural and technological evolution of Amazon retail websites starting with 1994 and ending with adopting Amazon Web Services.
Michael Stal discusses system architecture quality, how to avoid architectural erosion, how to deal with refactoring, and design principles for architecture evolution.
Every developer has had to integrate with another system, API or component. Tis article provides strategies to handle the change and for he separating system boundaries.
No comments
Watch Thread Reply