Read my latest article: Announcing RailsDeveloper (posted Wed, 01 Sep 2010 17:01:00 GMT)

The bitter-sweet taste of agnostic database schemas

Posted by Robby Russell Tue, 27 Sep 2005 13:41:00 GMT

29 comments Latest by Coach Handbags Sat, 14 Aug 2010 07:12:30 GMT

If you know me at all by now… you might know that I am a huge fan of PostgreSQL. Coming to the Rails camp was a bit of an eye-opener./ Working with PostgreSQL used to save me quite a bit of work and let me sleep at night. I have dealt with the problems that many developers face while working with MySQL. Like many of us in the Open Source world, I was exposed to MySQL more often than PostgreSQL. For several years, I convinced myself that MySQL was awesome because it was fast… but speed isn’t always the most important factor in the technology world. Otherwise, we’d all be coding in C. What PostgreSQL provided to me as a developer was better relational integrity. Foo cannot exist unless Bar does, or vice versa. ON DELETE CASCADE was a godsend and saved me quite a bit of work when building an application. Triggers… Procedural Languages… oh so beautiful.

PostgreSQL was (and is) the Open Source database server that both the Enterprise DBA and Developer could agree on.

Enter Ruby on Rails

At first, I just ignored my instincts and jumped in head first. Pluralization? Primary keys named id? Blasphemy! Yet, I moved forward. After a few days of consistently reminding myself of these new-fangled conventions (I even printed out a little cheat sheet and taped it to my monitor)... I was hooked. Rails worked with PostgreSQL. Let me say that again.

RAILS WORKS WITH POSTGRESQL!

Don’t freak out. Yes, the person who started the Rails project is a MySQL fan... but Rails is database agnostic. It’s true.

I wanted to write an entry to clear up a few myths about Rails.

  • Table names are not forced
  • Primary Key field names are not forced
  • Foriegn Key field names are not forced
  • Legacy databases can work with Rails
  • Active Record (like much of Rails) can be customized for your particular application’s needs

I was, and still am, concerned about trusting Active Record with handling my relational data… because in some cases it wasn’t doing what it should. But, that is being worked on… and because Rails is Open Source, the issue is transparent for us developers to see and help fix.

In the past, you might have found me advocating the addition of business logic in your database server, whenever possible. It is the gate keeper. The key master. It is not meant to be flexible with your data. If business rules are to change, you change them there so that if you have one or more INPUT streams into your database, the data will not get into your server unless your business rules are met. PostgreSQL even provides you with a nice ERROR message, which some other servers do not. If you can control everything through one INPUT stream (Application Database), then putting these constraints solely in your database abstraction layer is a-ok. However, if you are interfacing with your server through a variety of avenues (Integration Database), you probably already know that your system is going to be a pain to maintain in the long run. So, what are you to do?

Handling Legacy systems is going to be a headache, regardless of what you do… but you can’t always rebuild the whole thing and migrate your data. Add that to your Someday-Maybe list.

When you’re adding new pieces to your application, start by using good tools, frameworks, and practices. For example, try your best to follow the Application Database path to pragmatic enlightenment. Begin working on a new layer for your legacy database. Add on web services that use this layer. Refactor your existing applications. Can they use these new services? ReThink everything. That is… if you have the time and resources to do so.

If you are questioning whether or not to put your business logic in your database abstraction layer, stop. Just do it™. But, do it with caution. Test it. Test it well. I’ll admit that I still add some constraints into my database schemas-I am not ready to give up that extra layer of data security. But, that’s just me. :)

PostgreSQL works with Rails!

...and I promise to show you how to do some fun legacy stuff with Rails in my book. :-)

Subscribe to my RSS feed Enjoying the content? Be sure to subscribe to my RSS feed.
Comments

Leave a response

  1. Avatar
    ed hardy clothing Fri, 26 Mar 2010 01:31:02 GMT
  2. Avatar
    face blog Sat, 27 Mar 2010 09:57:31 GMT

    RAILS WORKS WITH POSTGRESQL??? wow, I have been using it with mysql and It is now I knew that I can use with pgsql as well.. I will test it…..

  3. Avatar
    banners Tue, 30 Mar 2010 07:15:35 GMT

    i’m using mysql for Rails ..but i like to have some experience with Postgre DB Server also .. thanks for giving this useful information

  4. Avatar
    ShAaNiG Thu, 08 Apr 2010 22:30:29 GMT

    nice one bro. thank you

    Wholesale Clothing

  5. Avatar
    ShAaNiG Sat, 10 Apr 2010 16:40:00 GMT

    i’m using mysql for Rails ..but i like to have some experience with Postgre DB Server also .. thanks for giving this useful information

    Wholesale Brand Name Clothing

  6. Avatar
    ShAaNiG Mon, 12 Apr 2010 12:07:08 GMT

    i’m using mysql for Rails ..but i like to have some experience with Postgre DB Server also .. thanks for giving this useful information

    Wholesalers

  7. Avatar
    auto parts Sat, 17 Apr 2010 06:16:12 GMT

    Thanks for giving this good information .I’ve Bookmarked this page for future reference.

  8. Avatar
    Angelahelm Mon, 03 May 2010 20:37:22 GMT

    I didn’t know that rails work with postgresol.

  9. Avatar
    links london Tue, 04 May 2010 01:03:39 GMT

    RAILS WORKS WITH POSTGRESQL??? wow, I have been using it with mysql and It is now I knew that I can use with pgsql as well.. I will test it…..

  10. Avatar
    Abercrombie Tue, 04 May 2010 06:54:12 GMT

    thanks for giving this useful information

  11. Avatar
    jordanmass Thu, 06 May 2010 00:56:25 GMT
  12. Avatar
    daniel Wed, 19 May 2010 10:46:32 GMT

    I have the same reaction with face blog. You have just enlightened me with PostgreSQL’s compatibility with Rails. Thanks for the information. I am ready to try PostgreSQL over MySQL.

    Filipino culture

  13. Avatar
    Kent Wed, 19 May 2010 14:12:29 GMT

    It really is good to try new stuff. I am new with the PostgreSQL with Rails biz and I am happy to know that somebody else is thrilled with working with Post instead of My.

    essay application

  14. Avatar
    Daniel Wed, 19 May 2010 16:52:15 GMT

    I like how you manage to dispel quite a few Rails myths for me in just one post. This is really important for somebody who is new to Rails like me. Thanks.

    no faxing payday loans

  15. Avatar
    ugg tasmina braid chocolate Fri, 28 May 2010 00:52:16 GMT

    ugg tasmina braid chocolate

  16. Avatar
    Adicolor Fri, 04 Jun 2010 00:14:28 GMT

    yui yui ty u

  17. Avatar
    AdiSTAR Ride Fri, 04 Jun 2010 00:14:37 GMT

    ytu tyty u

  18. Avatar
    air jordan 11 Wed, 30 Jun 2010 08:06:15 GMT

    Demonstrate a unique new conceptjordan shoesAw1

  19. Avatar
    free ringback tones Wed, 07 Jul 2010 16:04:32 GMT
  20. Avatar
    rubi.linkexpert@gmail.com Mon, 12 Jul 2010 12:52:53 GMT

    Online Shopping, Gifts, Clothes, Computer :- indiashoppingmalls..blogspot is an online shoping poral where you can shop for all type of Computer,electronic gadgets, clothes, fashion accessories,books,shoes and can gets lots of shopping tips.

    Find a New Car, Used Car, Used Cars :- If you own a driver’s license, then there is a good chance that you will find yourself doing quite a bit of night driving at some point in your life. For many people who are new to the wonderful world of driving, this most often occurs when you go away to college.

    Computer and Software, Computers Point Of Sale Systems and Software :- The present era is the age of wireless gadgets. The days of wired gadgets are now passé. The same can be said about wireless computer headsets. When headsets for computers were first introduced, they were of the wired variety.

    Computer and Software, Computers Point Of Sale Systems and Software :- Access the shared data offline allows you to keep using your shared files, folders and software programs when disconnected from the data server. When you reconnect to your data server, all files will be synchronized to the files on the network.

    Singapur Tour and Travel, Tour and Travel :- If you need a vacation get away try a park type, mobile home. That is unless you just have to have the extravagant vacation house and the best of everything. The reason for this kind of a home is that you are not, tied down to one location. You can take the travel trailer with you to any location you choose.

    Best India Seo Company, Best Seo company in india :- Search Engine Optimization or SEO, is one of the techniques which is used to make your own WebPages more useful and comfortable for your customers by making the WebPages more understandable and transparent to Search Engines. SEO is an economical method which favors your site to get more page views by forming WebPages that rank very high in Search Engine results.

    India property, Find a New Home :- Gurgaon, the fastest developing city in Haryana, belongs to Delhi’s NCR region. No other city has been able to showcase such rapid growth and transformation as Gurgaon. In a very short span of time, it has become the IT and BPO capital of India. It is all set to become one of the mega cities of the country.

    Star Web World | Search Engine Optimization | Web design | Computer graphics | Computer Softwares | Online Education

  21. Avatar
    umakant.webmaster@gmail.com Mon, 12 Jul 2010 12:56:36 GMT
  22. Avatar
    Discount Louis Vuitton Wed, 21 Jul 2010 16:45:04 GMT

    Louis Vuitton Zippy Coin Purse M6015N Louis Vuitton Zippy Coin Purse Louis Vuitton Zippy Coin Purse M6015M Louis Vuitton Zippy Coin Purse Louis Vuitton Zippy Coin Purse M60152 Louis Vuitton Zippy Coin Purse Louis Vuitton Zippy Coin Purse M6015J Louis Vuitton Zippy Coin Purse Louis Vuitton Zippy Coin Purse M6015K Louis Vuitton Zippy Coin Purse Louis Vuitton Zippy Wallet M6007N Louis Vuitton Zippy Wallet Louis Vuitton Zippy Wallet M6007M Louis Vuitton Zippy Wallet Louis Vuitton Zippy Wallet M6007K Louis Vuitton Zippy Wallet Louis Vuitton Zippy Wallet M6007J Louis Vuitton Zippy Wallet Louis Vuitton Zippy Wallet M60072 Louis Vuitton Zippy Wallet Louis Vuitton Zippy Organizer M6385N Louis Vuitton Zippy Organizer Louis Vuitton Zippy Organizer M63852 Louis Vuitton Zippy Organizer Louis Vuitton Zippy Organizer M6385K Louis Vuitton Zippy Organizer Louis Vuitton Zippy Organizer M6385J Louis Vuitton Zippy Organizer Louis Vuitton Joey Wallet M6658N Louis Vuitton Joey Wallet Louis Vuitton Joey Wallet M6658M Louis Vuitton Joey Wallet Louis Vuitton Joey Wallet M6658J Louis Vuitton Joey Wallet Louis Vuitton Joey Wallet M66582 Louis Vuitton Joey Wallet

  23. Avatar
    Raj saxena Thu, 22 Jul 2010 05:00:01 GMT
  24. Avatar
    wade Sat, 31 Jul 2010 06:28:40 GMT

    The contract, Ceglia said in omega men his complaint, also allowed him Vacheron Constantin Malte an additional 1 percent stake chanel replica jewelry in the business for each burberry scarf replica day after Jan. 1, 2004 Michele Deco until the website was completed. Tiffany Jewelry The website thefacebook.com, according to louis vuitton purses fake the lawsuit, was finished on juicy couture charm bracelet Feb. 4, 2004—a replica burberry 34-day span that would entitle tiffany rings Ceglia to another 34 percent Swiss Army Classic Infantry stake in the business, the Girard Perregaux Laureato EVO3 lawsuit said.

  25. Avatar
    e66 white Tue, 03 Aug 2010 09:05:45 GMT
  26. Avatar
    songhailing Wed, 04 Aug 2010 05:57:50 GMT

    I links of london realize my dream I have a store of the ornaments. I sell Links of London sweetie bracelets and Links of London sweetie rings as well as Links of London sweetie earrings. I links of london sale hope the girl wearing it is happy. I can realize the dream. When I links of london jewellery wear it, the boy hurt my heart. I can not forget these and I believe that perhaps he is not on purpose.

  27. Avatar
    cosmetic bag factory Mon, 09 Aug 2010 03:34:57 GMT

    greSQL. For several years, I convinced myself that MySQL was awesome be

  28. Avatar
    http://www.bestretroshoes.com Fri, 13 Aug 2010 08:49:04 GMT
    air jordan retro 1,air jordan retro 1
    air jordan retro 2,air jordan retro 2
    jordan ajf 20 shoes,jordan ajf 20 shoes
    air max 97,air max 97
    Air Jordan 2009,Air Jordan 2009
    Air Jordan Fusion 4,Air Jordan Fusion 4
    Air Jordan Force 13 Fusion,Air Jordan Force 13 Fusion
    Air Jordan Q4,Air Jordan Q4
    Air Jordan Flight Fusion 45,Air Jordan Flight Fusion 45
    Air Jordan Fusion 11,Air Jordan Fusion 11
  29. Avatar
    Coach Handbags Sat, 14 Aug 2010 07:12:30 GMT

    We are a professional exporter and wholesaler of brand fashion products,Coach Purse 0055 Red Coach Purse 0056 Black Coach Purse 0057 Black And Gray Coach Purse 0058 Black Coach Purse 0059 Brown And Yellow,All products have good quality,fast and safe delivery without shipping fee. Our primary goal is to meet our clients’ requirement and establish mutually pleasant business relationships with you.If you are interested, please do not hesitate to contact us.

Share your thoughts... (really...I want to hear them)

Comments