1

given these two tables

CREATE TABLE [dbo].[ASTROLOGY_SIGN](
  [SIGN_ID] [int] NOT NULL,
 CONSTRAINT [PK_ASTROLOGY_SIGN] PRIMARY KEY NONCLUSTERED 


CREATE TABLE [dbo].[ACTIVITY_MASTER](
  [ACTIVITY_ID] [int] IDENTITY(1,1) NOT NULL,
 CONSTRAINT [PK_ACTIVITY_MASTER] PRIMARY KEY NONCLUSTERED 

rails generates the following two entries in schema.rb

create_table "ASTROLOGY_SIGN", :id => false, :force => true do |t|
create_table "ACTIVITY_MASTER", :primary_key => "ACTIVITY_ID", :force => true do |t|

Trying to use the schema to move from sqlserver to postgres but this is giving me issues. There are a lot of tables and would rather not have to edit by hand.

4

1 回答 1

1

朋友可能会对您有所帮助...您的表及其在 SQLServer 中的列有一些关系作为连接关系。看:

select * from INFORMATION_SCHEMA.TABLES join INFORMATION_SCHEMA.COLUMNS on 
INFORMATION_SCHEMA.TABLES.TABLE_NAME = INFORMATION_SCHEMA.COLUMNS.TABLE_NAME

有了所有这些信息,您可以编写一个小程序来转换它们。我的意思是您可以访问有关您的表和列的这些信息,然后将它们替换为字符串,即在postgres .look 中查询的字符串:

for(every table in INFORMATION_SCHEMA.TABLES )
{
    string postgres_query = "create_table " + TABLE_NAME + ", :id => false, :force => true do |t|"
    exec(postgres_query)
}

然后为每个表执行它到 datacenter(postgres) 。当然,您必须将其优化为您真正想要的。您知道这不是正确的代码

于 2013-05-08T18:34:33.390 回答