Let there be stars

Yesterday, I went through some of the basic object modeling — Stars, Planets, and some classification systems for both of those things. The Star classifications are loosely taken from the Hertzsprung-Russel diagram, and will give the map a bit of color by having the Stars show up differently, maybe down the road these will have various impacts on their planets’ resource generation. The Planets each have an “atmosphere type”, one of several arbitrarily chosen gasses, which can have major impacts on how suitable they are for living on, or for setting up resource extraction.

I dug out the old migration file generated by the Django “South” plugin, and used that as a guide to the fields and object relations that existed in the old system. For now, the rails g scaffold command is getting me what I need out of these, just to get some stuff in the database and some interfaces on the web, but they will obviously all need heavy customization down the road.

I was also able to wire up the old url scheme, mapping /galaxy to the world map of the Stars, and get the planets arranged into paths like /star/:star_number/planet/:planet_number. I think, except in cases where I really “know better” now, I’m going to be attempting to mimic the last working codebase as much as possible just to get this thing running.

Thinking about the migrations file as a reference point, I will say the approach to migrations is a pretty interesting delta point between the two frameworks, and one I’m not sure which I actually prefer these days. Django’s database is explicitly driven by Model code, with all fields defined as class methods that return a type, and their migration library (call ‘South’… migrations get it?) inspects the Models, looks for changes from the last time it ran, and generates a file that will make the required SQL changes. Rails on the other hand, you explicitly define the migrations, what tables you want to create, add, modify etc., and it interrogates the database for the resulting ‘schema’, and uses that to automagically add accessors and other functionality to your Models.

Once upon a time, I really appreciated not needing to consider the DB so directly, but now I can also see use in carefully tuning the DB, then making sure the code handles the DB how I want. I do miss the ability to just check my Model code for the full list of attributes, though, instead of having to consult schema.rb every time.

Leave a Comment

Your email address will not be published. Required fields are marked *