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 1evaXG-0004Rj-QV for pgsql-general@arkaria.postgresql.org; Tue, 13 Mar 2018 03:23:34 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1evaXF-00039x-FM for pgsql-general@arkaria.postgresql.org; Tue, 13 Mar 2018 03:23:33 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1evaXF-00039e-6w for pgsql-general@lists.postgresql.org; Tue, 13 Mar 2018 03:23:33 +0000 Received: from ipmail06.adl2.internode.on.net ([150.101.137.129]) by magus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1evaX2-0008LC-Ed for pgsql-general@postgresql.org; Tue, 13 Mar 2018 03:23:30 +0000 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A2BTCQDh299Z/4SKZZZeHgYMgmqBV24ngy9LgSuJaKF8hnkthEmFZwECAQEBAQECayiFR24HPgJ6E4oCEaNGiByCJ4Rxhn2DLZEEgmEFoUSHXqAclyRXgQ6BA4IKgx+CWi02iRMrghkBAQE Received: from webmail1.internode.on.net (HELO localhost) ([150.101.138.132]) by ipmail06.adl2.internode.on.net with ESMTP; 13 Mar 2018 13:53:11 +1030 Message-Id: From: matt.figg@internode.on.net Reply-To: matt.figg@internode.on.net To: pgsql-general@postgresql.org X-Mailer: Atmail 6.20.12 Subject: Programmatically duplicating a schema Date: Tue, 13 Mar 2018 13:53:11 +1030 Content-Type: multipart/alternative; boundary="=_49d8c2218b7bbe636ea863b5bfcc3a3e" MIME-Version: 1.0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --=_49d8c2218b7bbe636ea863b5bfcc3a3e Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Hi all,=0AWhat is a reliable way to programmatically & generically popul= ate an=0Aempty schema with all the objects in the public schema as a tem= plate?=0AWe are using the multi tenancy ruby gem Apartment (=0Ahttps://g= ithub.com/influitive/apartment ), which was recently broken=0Aby the cha= nges made to pg_dump to address=C2=A0CVE-2018-1058=0Ahttps://nvd.nist.go= v/vuln/detail/CVE-2018-1058=0AApartment attempts to duplicate the public= schema whenever creating a=0Anew schema by running:=0Apg_dump -s -x -0= -n public=0Ato get the SQL statements needed to recreate the public sch= ema & then=0Aexecutes the pg_dump's sql output after creating & switchin= g to the=0Anew schema ( via set search_path to ; )=0AAfter the fix to CV= E-2018-1058, all table references in pg_dump's=0Aoutput (including withi= n SQL of stored procedures) are prefixed by the=0Apublic. schema, which= means you cannot just reuse this output in a=0Adifferent schema context= without first manually changing the sql.As a=0Atemporary fix so we can= handle new customers in production, we are=0Ausing a regex search/repla= ce for public. in the pg_dump output, but=0Aclearly this is not a reliab= le solution for a generic gem such as=0AApartment.=0AIs there a differen= t way this gem could now be achieving this?Without=0Aa flag on pg_dump t= o force the old format, or a CREATE SCHEMA WITH=0ATEMPLATE kind of sta= tement, we can't see any alternative more=0Areliable than the regex sear= ch/replace.=C2=A0=0AThe open issue on the Apartment gem for=0Acontext:= =C2=A0https://github.com/influitive/apartment/issues/532=0AThanks in adv= ance. --=_49d8c2218b7bbe636ea863b5bfcc3a3e Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Hi all,

What is a reliable way to progr= ammatically & generically populate an empty schema with all the obje= cts in the public schema as a template?

We ar= e using the multi tenancy ruby gem Apartment ( https://github.com/influi= tive/apartment ), which was recently broken by the changes made to pg_du= mp to address=C2=A0CVE-2018-1058 https://nvd.nist.gov/vuln/detail/CVE-20= 18-1058

Apartment attempts to duplicate the p= ublic schema whenever creating a new schema by running:

=
pg_dump -s -x -0 -n public

to get= the SQL statements needed to recreate the public schema & then exec= utes the pg_dump's sql output after creating & switching to the new= schema ( via set search_path to <new schema>; )

<= /div>
After the fix to CVE-2018-1058, all table references in pg_dum= p's output (including within SQL of stored procedures) are prefixed by t= he public. schema, which means you cannot just reuse this output in a di= fferent schema context without first manually changing the sql.
As a temporary fix so we can handle new customers in production, we ar= e using a regex search/replace for public. in the pg_dump output, but cl= early this is not a reliable solution for a generic gem such as Apartmen= t.

Is there a different way this gem could no= w be achieving this?
Without a flag on pg_dump to force the ol= d format, or a CREATE SCHEMA <schema_name> WITH TEMPLATE <other= _schema> kind of statement, we can't see any alternative more reliabl= e than the regex search/replace.=C2=A0

The op= en issue on the Apartment gem for context:=C2=A0https://github.com/influ= itive/apartment/issues/532

Thanks in advance.=
--=_49d8c2218b7bbe636ea863b5bfcc3a3e--