Immutable Database Schema

Immutable Database Schema

I’m adding functionality to a mature web application and need to add a field to a database table.  I started mentally walking the path of the change and what all it touches and the required testing and review that would ensue and it’s mildly daunting.

Then a voice in my head said, “immutability.”

The field I would add is not necessarily a record field – it’s not data, it’s relationship.  Is “relationship” data?

Instead of adding a field and reviewing and refactoring everywhere the model is used, I can simply add a relationship table, create a model and use it when needed.

Slightly more code, way less review.  But I don’t know if it’s a good approach, or if anyone else has tried this, so I’m documenting this online and asking for feedback.

Do you have an opinion about this?

Advertisements

PHP Exceptions and Namespaces

I’m way too late to the PHP namespace conversation. Initially I just didn’t see the benefit of namespaces, but now I’ve seen the light.  The other issue was the production environment at work didn’t support  namespaces – I own that problem too.  Basically for way too long it was a big fail fest.

But now angel choirs are singing and I’ve seen the light.  I preface this post with these details in case you already know what I’m about to write about.

I just spent 20 minutes trying to figure out why the same pattern of code worked in one place but not another.  I’m trying to validate date strings in form submissions and had some code like this:

function validateDate()
{
	try
	{
		$dt = new \DateTime( $fieldValue );
	}
	catch( Exception $e )
	{
		return false;
	}

	return true;
}

The error I was seeing was an uncaught exception for an invalid date format.  That’s exactly what I was trying to prevent!

It took me way too long to realize that I needed to namespace the Exception class.

The solution is either to

use Exception;

at the top of my class file or to rewrite the function.

function validateDate()
{
	try
	{
		$dt = new \DateTime( $fieldValue );
	}
	catch( \Exception $e )
	{
		return false;
	}

	return true;
}

 

TLDR: Make sure you namespace the class names in your catch blocks otherwise it’s ignored and the exception is not caught.

My Response to an Apology

Apology accepted. No worries – our culture is obsessed with perfection.

I’m convinced that everyone is faking it most of the time. True teamwork spans not just team members within your own daily circle of knowledge but all people you happen to come into contact with. Greatness is on the outer boundaries of our experience, waiting for us to admit our failures and shortcomings. Once we kill our pride and move that outer boundary closer to our center, we become truly great by empowering a fellow human being to step into a role they are wonderfully skilled to fulfill.

Hope your week gets better!

– Tim

 

Image: By Aleks G (Own work) [CC BY-SA 3.0 (http://creativecommons.org/licenses/by-sa/3.0)%5D, via Wikimedia Commons

Last Train Out

I’m in the last seat, on the last car
On the last train out, from the middle of here
I’ve left my bundle of worries, there at the station
On the platform, beside my little black heart

The conductor comes by, and tells the passengers
“You’d better have your tickets out and ready
Or we’ll throw you right off this here train.”
So I pat, paw, and dig around, and then… panic

I’m in the last seat, on the last car
I’m gonna get thrown off, I won’t get far
Right as I get up to go and hide, a Tall Stranger
Appears beside me, “Here you go, friend.”

I’m in the last seat, on the last car
Clutching my ticket, holding it tight.
I’m looking at a man, who gave up his
Gave it to me, and I don’t understand

When all of a sudden, just as he’s grabbed
Like a bolt, I know the truth, the awful truth
He had but one ticket, and gave it to me
And I realize this, as he’s taken away.

I get up to follow, everything is blurred
I hear the conductor say, “Just throw him off!”
So they threw the Stranger off my train
And I watched him bounce and roll, and roll

I kept watching as we clacked out of sight
And before I lost view, his body stopped
Still, and silent, and I knew exactly the price
The Tall Stranger had paid, back there on the tracks.

Selected Recent Tweets

 

 

 

 

 

 

Dreaming Dream Dreamers

(a Christmas poem)

It takes a fight to push back against the internal night
And a sacrifice to smile and stay in the fight
When hope lives near the raggedy edge of despairs
Leave the day’s failures behind and put my foot to the stairs

Step forward and up, with a deep breath; take score:
Four children and wife… Put my hand to the door
A push and I’m in where the air is ablaze and alight
Quick, shut the door to keep out the black night

Each one is a dreamer, each one is alive
Every single wonderful person inside
And they are all simply lovely, these people of mine
Each one is enthralling, like expensive fine wine

And each dreaming dream dreamer has their head in a cloud
With their thoughts and ideas, and it makes me feel proud
Kids! Kids! Kids!!! I must start by kissing your mother!
Her lips are fantastic… I must smooch! I must smother!

Goodness! Now that that’s over and done,
Let me hear of your day and all you’ve become
Tell me all that you’ve learned and the ideas you’ve had
I bet they’re all good – not a single one bad

Because all of you dreaming dream dreamers must know
I love you more now than I could possibly show.

IMG_3995