Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #4492 (new defect)

Opened 3 years ago

Last modified 1 year ago

[PATCH] PostgreSQL 'timestamp with time zone' columns get created as 'timestamp without time zone' columns in the test database

Reported by: drbrain@segment7.net Assigned to: rails@bitsweat.net
Priority: normal Milestone:
Component: ActiveRecord Version: 1.1.0 RC1
Severity: major Keywords: postgresql needs_review
Cc: fixtures, fotos

Description

$ psql trackmap_development
[...]
trackmap_development=# \d points
                                   Table "public.points"
    Column    |           Type           |                    Modifiers                    
--------------+--------------------------+-------------------------------------------------
 id           | integer                  | not null default nextval('points_id_seq'::text)
 route_id     | integer                  | not null
 position     | integer                  | 
 latitude     | double precision         | not null
 longitude    | double precision         | not null
 elevation    | integer                  | 
 time         | timestamp with time zone | 
 lock_version | integer                  | not null default 0
[...]

You can see the "time" column that has a type of 'timestamp with time zone' in my development database.

$ psql trackmap_test
[...]
trackmap_test=# \d points
                                        Table "public.points"
    Column    |            Type             |                        Modifiers                        
--------------+-----------------------------+---------------------------------------------------------
 id           | integer                     | not null default nextval('public.points_id_seq1'::text)
 route_id     | integer                     | not null
 position     | integer                     | 
 latitude     | double precision            | not null
 longitude    | double precision            | not null
 elevation    | integer                     | 
 time         | timestamp without time zone | 
 lock_version | integer                     | not null default 0
[...]

But after I run rake test and the test database gets created it was switched to 'timestamp without time zone'.

Rails should be preserving the 'with time zone' part of my timestamp.

Attachments

timezone.patch (4.8 kB) - added by zenspider on 03/30/06 01:39:49.
timezone support for abstract and postgresql
pg_utc_default_timezone.patch (0.6 kB) - added by Gerardo Malazdrewicz <gmalazdrewicz@gmail.com> on 04/26/06 17:47:49.
Fix for be able to use TIMESTAMP WITH TIME ZONE _AND_ Base.default_timezone = :utc

Change History

03/30/06 00:59:02 changed by nzkoz

Currently AR doesn't have a concept of 'timestamp' vs 'timestamp with timezone'. This should be fixed, but in the meantime make the following change to environment.rb

  # Use Active Record's schema dumper instead of SQL when creating the test database
  # (enables use of different database adapters for development and test environments)
  config.active_record.schema_format = :sql

Which will use pg_dump, mysqldump etc. instead of schema.rb

03/30/06 01:39:49 changed by zenspider

  • attachment timezone.patch added.

timezone support for abstract and postgresql

03/30/06 01:41:24 changed by zenspider

  • cc set to fixtures.
  • severity changed from normal to major.

I'm pretty sure the patch I just attached adds support for it. I can't fully tell tho because there are NO (worthwhile) unit tests for AR. That said, I hand tested it and it seems to work fine.

04/05/06 06:31:58 changed by anonymous

  • keywords changed from postrgesql to postrgesql needs_review.

See #4461 for info about multiple postgressql fixes in r4156. Just a heads up in case this patch won't apply cleanly anymore or if there are other conflicts.

04/05/06 16:45:01 changed by anonymous

  • summary changed from PostgreSQL 'timestamp with time zone' columns get created as 'timestamp without time zone' columns in the test database. to [PATCH] PostgreSQL 'timestamp with time zone' columns get created as 'timestamp without time zone' columns in the test database.

04/26/06 17:47:49 changed by Gerardo Malazdrewicz <gmalazdrewicz@gmail.com>

  • attachment pg_utc_default_timezone.patch added.

Fix for be able to use TIMESTAMP WITH TIME ZONE _AND_ Base.default_timezone = :utc

04/26/06 18:03:54 changed by Gerardo Malazdrewicz <gmalazdrewicz@gmail.com>

When you use TIMESTAMP WITH TIME ZONE, the time is retrieved by default using the local time zone representation. Further conversions discard the timezone data, then stamp the default time zone. All fine and dandy when the default time zone is :local, but gives incorrect time when it is :utc.

The attached patches tells Postgres the default time zone is UTC when AR is configured that way, fixing this anomaly.

07/03/06 01:47:14 changed by zenspider

I thought my patch was accepted (by bitsweat?)... what is the status of this?

07/05/06 01:27:48 changed by david

  • owner changed from David to rails@bitsweat.net.

04/25/07 23:58:26 changed by josh

  • keywords changed from postrgesql needs_review to postgresql needs_review.

07/05/07 02:40:50 changed by fotos

  • cc changed from fixtures to fixtures, fotos.

09/19/07 12:16:39 changed by bopm

So is there any updates on this issue?