pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Aldrin Martoq Ahumada <aldrin.martoq@gmail.com>
To: Andre Oliveira Freitas <afreitas@callixbrasil.com>
Cc: pgsql-general@lists.postgresql.org
Subject: Re: Postgresql upgrade to 9.5.12/10.3 changes pg_dump format for cloning schemas
Date: Fri, 9 Mar 2018 12:00:43 -0300
Message-ID: <1D546CA9-B443-4CE9-A43F-EE70D70DAA9E@gmail.com> (raw)
In-Reply-To: <CAN6ijTAhW9f08z6GkASVKMWV-FmwFbfYALyZVmGzCL_fzD18-g@mail.gmail.com>
References: <ED39C2F0-21E9-4F7C-B0CF-14A62E78AFD6@gmail.com>
	<CAN6ijTAhW9f08z6GkASVKMWV-FmwFbfYALyZVmGzCL_fzD18-g@mail.gmail.com>

Hi Andre,

Yes, here is the issue: https://github.com/influitive/apartment/issues/532 <https://github.com/influitive/apartment/issues/532;

It happens if you configured apartment with use_sql=true, which means it clones the schema from pg_dump. My first attempt was to “fix” the script generated by pg_dump, but I feel it will be a mess. We solved our issue going back to use_sql=false, which is the default (creates the schema from db/schema.rb). But there is people that have other requirements, like functions, so the easier way for them is to keep use_sql and replace strings in the script.


Cheers,

> On Mar 9, 2018, at 11:51 AM, Andre Oliveira Freitas <afreitas@callixbrasil.com> wrote:
> 
> Hello Aldrin,
> 
> I'm also using apartment with postgresql 9.6.6, and I don't see any
> issue with it. Are you using Apartment::Tenant.create?
> 
> 2018-03-09 10:26 GMT-03:00 Aldrin Martoq Ahumada <aldrin.martoq@gmail.com>:
>> Hi,
>> 
>> For a multi tenant system, we are using the following command to blindly
>> clone a schema into another:
>> pg_dump -s -x -O -n #{default_tenant} #{dbname}
>> 
>> 
>> This is done for us by a rails gem, which then feeds that script into the
>> new created schema for the new tenant.
>> https://github.com/influitive/apartment/blob/80a21f2e1cdcbe5b0bd976f88c14332657804536/lib/apartment/...
>> 
>> 
>> 
>> 
>> When we upgraded from 9.5.11 to 9.5.12, the format of the dump changed (it
>> now always appends the schema name), so this is broken. We could patch the
>> SQL generated, but that’s not a generic/robust solution.
>> 
>> # pg_dump postgresql 9.5.11
>> SET search_path = public, pg_catalog;
>> CREATE TABLE ahoy_events (
>>    id bigint NOT NULL,
>>    visit_id integer,
>>    user_id integer,
>>    name character varying,
>>    properties jsonb,
>>    "time" timestamp without time zone
>> );
>> 
>> # pg_dump postgresql 9.5.12
>> CREATE TABLE public.ahoy_events (
>>    id bigint NOT NULL,
>>    visit_id integer,
>>    user_id integer,
>>    name character varying,
>>    properties jsonb,
>>    "time" timestamp without time zone
>> );
>> 
>> 
>> 
>> Thinking in the long term, how could be the best way to clone a schema into
>> another?
>> 
>> 
>> 
>> 
>> —
>> Aldrin
>> 
> 
> 
> 
> -- 
> 
> André Luis O. Freitas
> System Architect
> 
> Rua do Rócio, 220 - Cj. 72
> São Paulo - SP - 04552-000
> 55 11 4063 4222
> 
> afreitas@callix.com.br
> www.callix.com.br

view thread (8+ messages)  latest in thread

Message-ID: <1D546CA9-B443-4CE9-A43F-EE70D70DAA9E@gmail.com>
Permalink:  ../1D546CA9-B443-4CE9-A43F-EE70D70DAA9E@gmail.com/
Also on:    postgresql.org/message-id/1D546CA9-B443-4CE9-A43F-EE70D70DAA9E@gmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: aldrin.martoq@gmail.com, afreitas@callixbrasil.com
  Subject: Re: Postgresql upgrade to 9.5.12/10.3 changes pg_dump format for cloning schemas
  In-Reply-To: <1D546CA9-B443-4CE9-A43F-EE70D70DAA9E@gmail.com>
  References: <ED39C2F0-21E9-4F7C-B0CF-14A62E78AFD6@gmail.com> <CAN6ijTAhW9f08z6GkASVKMWV-FmwFbfYALyZVmGzCL_fzD18-g@mail.gmail.com> <1D546CA9-B443-4CE9-A43F-EE70D70DAA9E@gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox