Warning: Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.

Ticket #1249 (closed enhancement: fixed)

Opened 12 years ago

Last modified 8 years ago

Add arguments to tg-admin to specify a common prefix for TG related db tables

Reported by: chrisz Owned by: anonymous
Priority: normal Milestone: 1.5
Component: Identity Version: 1.0
Severity: normal Keywords: table names user_group visit


The users and groups tables are called tg_users and tg_groups which is good because the prefix helps distinguish them from the other application tables. However, the intermediate table is called user_group which is pretty unreasonable. It should be called tg_user_group instead . Same problem for the following tables:

  • visit
  • visit_identity
  • user_group
  • permission
  • group_permission

They all should get a tg_ prefix.

This was actually solved with ticket #76 so I wonder how that sneaked in again?

Anyway, here is a patch against the trunk that adds the tg_ prefixes, but does not use namespaces as in #76.


tg_tables.patch Download (3.7 KB) - added by chrisz 12 years ago.
Adds tg_ prefixes to the identity tables.

Change History

Changed 12 years ago by chrisz

Adds tg_ prefixes to the identity tables.

comment:1 Changed 12 years ago by jeffk

I thought the reason for the tg_ prefix was simply a name mangling to avoid collision with SQL keywords. The rule for becomes simpler in that case: add a tg_ (or other) prefix if your generated database object collides with a SQL keyword. This includes objects other those used by identity.

The current identity implementation is at this point only a commonly-used convention, and frequently modified, correct? As such, I don't think all five objects warrant reserving tg_ names.

I do appreciate the attention to being consistent with the intermediate_table. tg_user_tg_group, although ugly, would be accurate if one wanted to carry the mangled name consistently throughout. It may be better to keep the easy to read user_group than the easy to search-replace tg_user_tg_group

comment:2 Changed 12 years ago by chrisz

Ok, that may be the explanation why it was done with user and group (which may collide with SQL keywords) but not with user_group. Anyway I think it makes sense to stay consistend and also separate the tables which belong to the TurboGears framework from the tables you define for your application. Simply add the prefix tg_ to all of the standard tables. So instead of tg_user_tg_group I suggested a simple tg_user_group.

This is particularly important for legacy databases with hundreds of predefined tables that you want to access via a TurboGears application (in addition to legacy applications maybe). Then it is good if all additional tables from TurboGears are recognizable by the common tg_ suffix and are sorted along with each other in the database browser.

comment:3 Changed 12 years ago by Chris Arndt

I think table name prefixes are generally a good thing, but the main use for them I see is, when you use the same database for different applications (TG or others) and want to avoid name clashes between them. In this case, you would probably have a name prefix specific to your application, that would be prepended to the TG standard tables too. Then you would need to modify the model from the quickstart-generated one anyway.

A better patch, IMHO, would add an argument to "tg-admin quickstart" that allows to specify a general table prefix for all generated model tables.

comment:4 Changed 12 years ago by alberto

  • Summary changed from Identity table names still not consistent to Add arguments to tg-admin to specify a common prefix for TG related db tables
  • Milestone changed from 1.0.2 to 1.1

I agree with Chris, better resolve this in a more general way. Besides that, the patch would break code from apps running 1.0.1 due to the change in the tables' names.

This change must be documented in the migration guide.

Changing subject and moving to 1.1


comment:5 Changed 11 years ago by faide

  • Milestone changed from 1.1 to 1.1.1

comment:6 Changed 11 years ago by faide

  • Milestone changed from 1.6 to 1.5

comment:7 Changed 8 years ago by chrisz

  • Status changed from new to closed
  • Resolution set to fixed

Implemented in r7248.

Note: See TracTickets for help on using tickets.