# How do you define database tables?

**URL:** <https://www.ruby-forum.com/t/how-do-you-define-database-tables/49175>\
**Category:** Rails\
**Created:** [November 17, 2005, 12:17am UTC](https://www.ruby-forum.com/t/how-do-you-define-database-tables/49175 "2005-11-17T00:17:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![petermichaux](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/46a35a/32.png) [@petermichaux](https://www.ruby-forum.com/u/petermichaux)\
**Post date:** [November 17, 2005, 12:17am UTC](https://www.ruby-forum.com/t/how-do-you-define-database-tables/49175/1 "2005-11-17T00:17:35Z")

</div>

Hi,  
I was asking before if people use the ActiveRecord create table method  
to  
ensure portable table definitions. Seems like no one does it that way. I  
wonder why and also if people are so interested in database abstraction  
then  
how do they avoid writing raw SQL.  
Thanks,  
Peter

---

<div class="post-metadata">

**Author:** ![petermichaux](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/46a35a/32.png) [@petermichaux](https://www.ruby-forum.com/u/petermichaux)\
**Post date:** [November 17, 2005, 12:35am UTC](https://www.ruby-forum.com/t/how-do-you-define-database-tables/49175/2 "2005-11-17T00:35:40Z")

</div>

Peter M. wrote:

> Hi,
> 
> I was asking before if people use the ActiveRecord create table  
> method  
> to ensure portable table definitions. Seems like no one does it that  
> way. I wonder why and also if people are so interested in database  
> abstraction then how do they avoid writing raw SQL.

We’re working on a project with about 40 tables (about 10 of them join  
tables). We started in a spreadsheet, then moved to a sql file full of  
creates and permission settings, and now modify and keep that file up to  
date as we work.

Most things we do (CRUD) is abstracted, but some things have to be  
semi-raw or raw.

The Rails book (agile dev with Rails) seems to assume you would start  
with SQL definitions. It seems easier that way to get permissions,  
defaults, etc. set up. I’m not sure if using AR would make things any  
easier (for us anyway) and I don’t know if it we could have been able to  
set permissions and other attributes as easily.

Phil

---

<div class="post-metadata">

**Author:** ![petermichaux](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/46a35a/32.png) [@petermichaux](https://www.ruby-forum.com/u/petermichaux)\
**Post date:** [November 17, 2005, 12:38am UTC](https://www.ruby-forum.com/t/how-do-you-define-database-tables/49175/3 "2005-11-17T00:38:40Z")

</div>

Peter M. wrote:

> Hi,
> 
> I was asking before if people use the ActiveRecord create table method  
> to ensure portable table definitions. Seems like no one does it that  
> way. I wonder why and also if people are so interested in database  
> abstraction then how do they avoid writing raw SQL.

I can only answer for myself, but AR migrations are perfectly good  
enough for me, as long as I don’t feel the need to pull in from ODBC or  
write to SQLite. But those are just constraints of the environment I’m  
in, and pretty variable at that.
