Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1evlxj-0002hZ-V8 for pgsql-general@arkaria.postgresql.org; Tue, 13 Mar 2018 15:35:40 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1evlxi-0006D8-H0 for pgsql-general@arkaria.postgresql.org; Tue, 13 Mar 2018 15:35:38 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1evlxi-0006Cy-3j for pgsql-general@lists.postgresql.org; Tue, 13 Mar 2018 15:35:38 +0000 Received: from mail-qk0-x243.google.com ([2607:f8b0:400d:c09::243]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1evlxe-0003nJ-Fx for pgsql-general@lists.postgresql.org; Tue, 13 Mar 2018 15:35:36 +0000 Received: by mail-qk0-x243.google.com with SMTP id s78so5149qkl.8 for ; Tue, 13 Mar 2018 08:35:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:message-id:mime-version:subject:date:in-reply-to:cc:to :references; bh=R0BJcQcgqd4zuPqQDYdsaO9bHItiTb2NearTcr5Lhog=; b=X1THc77llMcXyCFoWGBVChYAELiSdSQrrKWgDbJsTo05tStd+OmNHRyDv1QBE938q1 746eshcAAw1ErKlW/leSqDsqzSEadZSQEHIouaoucaq7X6YsKpZqJssjQbkKjv+b6LuD PSz4FnDF8zPSlxhDg0pjsQYnSy41y9ywCCGNFuLWZrLXyQpWuPxpzovMQEidwFbY7ejk TD2aBxwz/78t1lWJLyhYaDDsmyVQ5rfzQtMSZxGpkUkZVdmE23dVKyPMTV86d86AucBy yJEzERb4tBHIeKF6Lzmx0bVct9RwwX+5+AptCNfG8JYbu/CqYYks1VzIz8o4kMwbAe1g 2v4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:message-id:mime-version:subject:date :in-reply-to:cc:to:references; bh=R0BJcQcgqd4zuPqQDYdsaO9bHItiTb2NearTcr5Lhog=; b=WPolq1xhQ59I12iPiX+UBGUketkRbCMYgx7JnX64xrzFmGHnwr9LE/pXM7cxrRWEbW nID1lqgwebkOYlwW7nR4BBbaGjlvJaxx72wPdGJd7jvV8WBVJCNNbsJwYBghGH+mBqS8 mTh9+rogldoeypA0Nsu8ksG1xLucj/+jOy5dj6E6JBBEgrH3ewhiYv2zLI+JymNyK+Uv tVqMi62VwxswGXTCoEJfmlIjx+LHM29sSuEfJeHaQKczWR/ubflU6f0thfCGTYkCDI1h VwaVAXXnMGWcDCwQJRnSM7i66s4CumU92cmqqCPPd6C5kGaSd20+Zfa0pS5XnBO+g0t/ inBQ== X-Gm-Message-State: AElRT7FWzRt7VpIZYfcb9uIIJ1r1ZapZzSC5Un4luuMDwUpwR6eR6lfL z5xVZjSlfgD26zDKbwbWzwQ= X-Google-Smtp-Source: AG47ELsuLbYz17cgOT+8X+CqqN1wYMkR5sX+NO4bAXbEoTUMmjw8CyJLKTJv3IBl0urg4dNGbGROLg== X-Received: by 10.55.157.66 with SMTP id g63mr1607566qke.107.1520955333598; Tue, 13 Mar 2018 08:35:33 -0700 (PDT) Received: from [10.0.111.50] (pc-92-113-120-200.cm.vtr.net. [200.120.113.92]) by smtp.gmail.com with ESMTPSA id m3sm335967qkb.64.2018.03.13.08.35.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 13 Mar 2018 08:35:32 -0700 (PDT) From: Aldrin Martoq Ahumada Message-Id: Content-Type: multipart/alternative; boundary="Apple-Mail=_FF584A05-A791-41B9-90C4-A3D3677008FE" Mime-Version: 1.0 (Mac OS X Mail 11.2 \(3445.5.20\)) Subject: Re: Postgresql upgrade to 9.5.12/10.3 changes pg_dump format for cloning schemas Date: Tue, 13 Mar 2018 12:35:29 -0300 In-Reply-To: Cc: Andre Oliveira Freitas , "pgsql-generallists.postgresql.org" , matt.figg@internode.on.net To: Melvin Davidson References: <1D546CA9-B443-4CE9-A43F-EE70D70DAA9E@gmail.com> X-Mailer: Apple Mail (2.3445.5.20) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --Apple-Mail=_FF584A05-A791-41B9-90C4-A3D3677008FE Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > On Mar 9, 2018, at 12:15 PM, Melvin Davidson = wrote: > On Fri, Mar 9, 2018 at 10:00 AM, Aldrin Martoq Ahumada = > wrote: > Yes, here is the issue: = https://github.com/influitive/apartment/issues/532 = > It happens if you configured apartment with use_sql=3Dtrue, which = means it clones the schema from pg_dump. My first attempt was to = =E2=80=9Cfix=E2=80=9D the script generated by pg_dump, but I feel it = will be a mess. We solved our issue going back to use_sql=3Dfalse, 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. > >...how could be the best way to clone a schema into another? > =20 > The safest way is to use pgdump -F p -n > = schema.sql > Then edit schema.sql and change all references to old_schema name to = new_schema name. > Finally, use psql < schema.sql to create the new_schema. > =20 > That being said, a year ago I optimized a function originally written = by Emanuel '3manuek' > called clone_schema, which is added to the public schema. It clones = all sequences, tables,=20 > indexes, rules, triggers, data(optional), views & functions from any = existing schema to a=20 > new schema > SAMPLE CALL: > SELECT clone_schema('public', 'new_schema', TRUE); > =20 > I've attached it for your convenience. > disclaimer: I do not accept any responsibility for any unknow bugs in = the function.=20 > Test first and use at your own risk. Thank you Melvin, I forgot to mention I've already found your script = before I asked here, but I didn=E2=80=99t think it was robust enough = (please don't offend :-). Particularly, it didn't work well on = PostgreSQL 10. I think the solution for the long term is to add a flag to pg_dump, but = in the short/mid term we=E2=80=99ll have to replicate some form of your = script into the gem. Cheers, Aldrin. PS: I=E2=80=99ve added initial support for PostgreSQL 10 to clone_schema = here, but I have no time to test it well: https://gist.github.com/aldrinmartoq/5df0aa03f86f3ad03982c793753c04a1 = --Apple-Mail=_FF584A05-A791-41B9-90C4-A3D3677008FE Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8

On Mar 9, 2018, at 12:15 PM, Melvin Davidson <melvin6925@gmail.com> wrote:
On Fri, Mar 9, 2018 at = 10:00 AM, Aldrin Martoq Ahumada <aldrin.martoq@gmail.com> wrote:
It happens if you configured apartment with use_sql=3Dtrue, = which means it clones the schema from pg_dump. My first attempt was to = =E2=80=9Cfix=E2=80=9D the script generated by pg_dump, but I feel it = will be a mess. We solved our issue going back to use_sql=3Dfalse, 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.
 >...how = could be the best way to clone a schema into another?
 
 The safest way is to use pgdump -F = p -n <the_schema_name> > schema.sql
 Then = edit schema.sql and change all references to old_schema name to = new_schema name.
 Finally, use psql < schema.sql = to create the new_schema.
 
 That = being said, a year ago I optimized a function originally written by = Emanuel '3manuek'
 called clone_schema, which is = added to the public schema. It clones all sequences, tables,
 indexes, rules, triggers, data(optional), views & = functions from any existing schema to a
 new  = schema
 SAMPLE CALL:
 SELECT = clone_schema('public', 'new_schema', TRUE);
 
 I've = attached it for your convenience.
 disclaimer: I = do not accept any responsibility for any unknow bugs in the function. =
 Test first and use at your own risk.


Thank you Melvin, I forgot to mention I've = already found your script before I asked here, but I didn=E2=80=99t = think it was robust enough (please don't offend :-). Particularly, it = didn't work well on PostgreSQL 10.


I = think the solution for the long term is to add a flag to pg_dump, but in = the short/mid term we=E2=80=99ll have to replicate some form of your = script into the gem.


Cheers,
Aldrin.

PS: I=E2=80=99ve added initial support for PostgreSQL 10 to = clone_schema here, but I have no time to test it well:


= --Apple-Mail=_FF584A05-A791-41B9-90C4-A3D3677008FE--