goose is a Database Migration manager written in Golang. (There’s another migration tool in Python called goose as well).
The documentation is a bit thin on the ground at present, and required a bit of code-reading. Conceptually, it is simple and easy to grok. Goose generates a series of timestamped migration files, which contains either raw SQL or go code, which can then execute Raw SQL statements. For better or worse, there is no ORM involved.
Here’s the basic configuration for connecting to mysql databases. (Note the driver is mymysql not mysql)
The simplest way to write the migration is using SQL (since I didn’t know much Go at all)
goose create SampleTable sql
in the db/migrations/20140601001151_SampleTable.sql we can modify it to the following
-- +goose Up
-- SQL in section 'Up' is executed when this migration is applied
CREATE TABLE sample
(id int primary key auto_increment,
-- +goose Down
-- SQL section 'Down' is executed when this migration is rolled back
DROP TABLE sample;
There are some peculiarities when working with 4D databases and .NET
Date time 0/00/0 12:00
0/00/0 12:00 is valid in ODBC, but not valid in .NET.
Recommendation – wrap all date calls with a CAST
e.g. SELECT CAST(BIRTHDAY AS VARCHAR) AS BIRTHDAY
alternatively, use a CASE statement to convert this call to something palatable to 4D e.g.
CASE CAST(LASTSEENDATE AS VARCHAR) WHEN '0/00/0 12:00:00' THEN CAST('1/1/1970' AS TIMESTAMP) ELSE LASTSEENDATE END AS LASTSEENDATE
Other alternatives simply don’t work. e.g. ... THEN NULL ELSE ... and NULLIF()
I wanted to be able to build extmap.xml for all the files that were in my packages\ directory. I had a Powershell script called ToExtMap which automated most of my tasks, and a little experimentation with Powershell gave me this one liner:
It started with making one presentation slide for each idea. Each slide would have a heading and several bullet points defining the scope of the feature and metrics describing what success would look like and how it would impact the business. That’s all people got to make their case. And given the speed of the whole process, there was little time for precision.
The first problem is the OrderDate is unintialized and renders as 0/00/0000.
The first thought is to change the OrderDate from DateTime to Nullable<DateTime>. This will require either the database schema be changed, or a second viewmodel created. Changing the database schema just to support a user-interface tweak is obviously out of the question. However, writing a viewmodel and copying all the properties over breaks a rule of “DRY” (Don’t Repeat Yourself).
Luckily, XAML binding supports the notion of binding converters. This lets us transforms inputs from one type to another.
public class NullValueConverter : IValueConverter
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
if (value is DateTime && targetType == typeof(Nullable<DateTime>))
if ((DateTime)value == DateTime.MinValue)
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
Applying the converter to the date picker, we get reasonably good results. For example, after entering a date and then clearing it, we get a validation error showing (see picture below). Furthermore, hitting cancel restores the control back to default value.
This done, we are ready to tackle our next problem.