# schema for straw (rss aggregator)

**URL:** <https://discuss.rubyonrails.org/t/schema-for-straw-rss-aggregator/20645>\
**Category:** rubyonrails-talk\
**Created:** [November 20, 2007, 9:36am UTC](https://discuss.rubyonrails.org/t/schema-for-straw-rss-aggregator/20645 "2007-11-20T09:36:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Thufir](https://avatars.discourse-cdn.com/v4/letter/t/ee7513/32.png) [@Thufir](https://discuss.rubyonrails.org/u/Thufir)\
**Post date:** [November 20, 2007, 9:36am UTC](https://discuss.rubyonrails.org/t/schema-for-straw-rss-aggregator/20645/1 "2007-11-20T09:36:27Z")

</div>

I would like to build an application on top of the following schema, but, of course, it would be preferable to make the schema compatible with the rails naming conventions so that things work as smoothly as possible 🙂

The current schema for straw:

&nbsp;&nbsp;85 dbSql =

&nbsp;&nbsp;86

&nbsp;&nbsp;87 dbSql.append('''

&nbsp;&nbsp;88 CREATE TABLE IF NOT EXISTS feeds (

&nbsp;&nbsp;89 id INTEGER PRIMARY KEY,

&nbsp;&nbsp;90 title TEXT,

&nbsp;&nbsp;91 location VARCHAR(255),

&nbsp;&nbsp;92 category\_id INTEGER

&nbsp;&nbsp;93 );''');

&nbsp;&nbsp;94

&nbsp;&nbsp;95 dbSql.append('''

&nbsp;&nbsp;96 CREATE TABLE IF NOT EXISTS items (

&nbsp;&nbsp;97 id INTEGER PRIMARY KEY,

&nbsp;&nbsp;98 title TEXT NOT NULL,

&nbsp;&nbsp;99 feed\_id INTEGER NOT NULL,

100 is\_read INTEGER NOT NULL DEFAULT 0,

101 link TEXT NOT NULL,

102 pub\_date TIMESTAMP NOT NULL,

103 description TEXT NOT NULL

104 );''')

105

106 dbSql.append('''

107 CREATE TABLE IF NOT EXISTS categories (

108 id INTEGER PRIMARY KEY,

109 parent\_id INTEGER,

110 title TEXT

111 );''')

112

113 dbSql.append('''INSERT INTO categories (parent\_id, title) VALUES (NULL, 'root');''')

114

115 dbSql.append('''

116 CREATE TABLE IF NOT EXISTS treeview\_nodes (

117 id INTEGER PRIMARY KEY,

118 obj\_id INTEGER NOT NULL,

119 norder INTEGER NOT NULL,

120 type VARCHAR(1) NOT NULL

121 );''')

\<[http://repo.or.cz/w/straw/fork.git?a=blob;f=straw/storage/](http://repo.or.cz/w/straw/fork.git?a=blob;f=straw/storage/) SQLiteStorage.py;h=aeb1fc418c162bdc082d8bcc7dbc6a8e1af9b2a5;hb=dfaf7eb7f1206746a2d8d43be0e81ed396ef711c\>

I don't really have enough knowledge as to what specific changes to propose. The tables look to be plurals, which is good, I know.  
According to \<[http://wiki.rubyonrails.org/rails/pages/](http://wiki.rubyonrails.org/rails/pages/)

> this is pretty much the only schema requirement.

Would this qualify as a legacy database? If so, why and what can be done to change that?

thanks,

Thufir

---

<div class="post-metadata">

**Author:** ![Frederick\_Cheung](https://sea2.discourse-cdn.com/rubyonrails/user_avatar/discuss.rubyonrails.org/frederick_cheung/32/3901_2.png) [@Frederick\_Cheung](https://discuss.rubyonrails.org/u/Frederick_Cheung)\
**Post date:** [November 20, 2007, 9:50am UTC](https://discuss.rubyonrails.org/t/schema-for-straw-rss-aggregator/20645/2 "2007-11-20T09:50:10Z")

</div>

> I would like to build an application on top of the following schema, but, of course, it would be preferable to make the schema compatible with the rails naming conventions so that things work as smoothly as possible 🙂

this seems mostly sensible. as you say the table names are plural and the foreign key columns are of the form singular-table\_id.

The one thing that is nonstandard

> 116 CREATE TABLE IF NOT EXISTS treeview\_nodes (
> 
> 117 id INTEGER PRIMARY KEY,
> 
> 118 obj\_id INTEGER NOT NULL,
> 
> 119 norder INTEGER NOT NULL,
> 
> 120 type VARCHAR(1) NOT NULL
> 
> 121 );''')

By default activerecord uses the type column for single table inheritance. You can of course change this

Fred

---

<div class="post-metadata">

**Author:** ![Thufir](https://avatars.discourse-cdn.com/v4/letter/t/ee7513/32.png) [@Thufir](https://discuss.rubyonrails.org/u/Thufir)\
**Post date:** [November 20, 2007, 10:09am UTC](https://discuss.rubyonrails.org/t/schema-for-straw-rss-aggregator/20645/3 "2007-11-20T10:09:35Z")

</div>

> The one thing that is nonstandard
> 
> > 116 CREATE TABLE IF NOT EXISTS treeview\_nodes (

[...]

> By default activerecord uses the type column for single table inheritance. You can of course change this

Ahem, pretend this is a bit new for me: What do you mean by type column? What do you mean by single table inheritance?

What if that table name were changed to either "views" or "nodes" or "TreeViewNodes" or similar? Or was it the name of the fields for this table?

thanks,

Thufir

---

<div class="post-metadata">

**Author:** ![Frederick\_Cheung](https://sea2.discourse-cdn.com/rubyonrails/user_avatar/discuss.rubyonrails.org/frederick_cheung/32/3901_2.png) [@Frederick\_Cheung](https://discuss.rubyonrails.org/u/Frederick_Cheung)\
**Post date:** [November 20, 2007, 10:32am UTC](https://discuss.rubyonrails.org/t/schema-for-straw-rss-aggregator/20645/4 "2007-11-20T10:32:05Z")

</div>

Well you've got a column called 'type'. I'll leave it up to you to google single table inheritance but the short version is that when you call Product.find(123) you get back a subclass of product. Rails uses the value of the type column to decide what class to instantiate.

Fred
