PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, April 14, 2022

[FIXED] How to create a geography and double precision database columns in Rails

 April 14, 2022     migration, postgresql, ruby-on-rails     No comments   

Issue

I would like to create a table like with this postgresql query. How to made a rails migration with a DOUBLE PRECISION and Geography column ?

CREATE TABLE poi_trace (
    poi_id BIGINT REFERENCES pois(id),
    trace_id BIGINT REFERENCES traces(id),
    geog GEOGRAPHY(Point, 4326),
    advance_on_trace DOUBLE PRECISION,
    active BOOLEAN
);

Solution

You can run custom sql in migrations

class ExampleMigration < ActiveRecord::Migration
  def up
    execute <<-SQL
      CREATE TABLE poi_trace (
        poi_id BIGINT REFERENCES pois(id),
        trace_id BIGINT REFERENCES traces(id),
        geog GEOGRAPHY(Point, 4326),
        advance_on_trace DOUBLE PRECISION,
        active BOOLEAN
      );
    SQL
  end
 
  def down
    drop_table :poi_trace
  end
end

Read more about this



Answered By - Eyeslandic
Answer Checked By - Pedro (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing