Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1os8Zk-0000jR-7h for pgsql-admin@arkaria.postgresql.org; Mon, 07 Nov 2022 20:18:32 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1os8Zj-0000Bw-0y for pgsql-admin@arkaria.postgresql.org; Mon, 07 Nov 2022 20:18:31 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1os8Zi-0000Bm-KM for pgsql-admin@lists.postgresql.org; Mon, 07 Nov 2022 20:18:30 +0000 Received: from mail-oi1-x22b.google.com ([2607:f8b0:4864:20::22b]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1os8Zf-0008D2-8R for pgsql-admin@lists.postgresql.org; Mon, 07 Nov 2022 20:18:30 +0000 Received: by mail-oi1-x22b.google.com with SMTP id b124so13399286oia.4 for ; Mon, 07 Nov 2022 12:18:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=jG14i4xv6bNS+aKciakq0Caf4sgXzsuaBf2KUiAn4fM=; b=hiwQwGybyzNbXJVC1juiG6aeqUtpq4R+EJF19cRDeWn9rQ+VB1ZbuUyvhKZn9mSwcA ETLap+J8YxF0SHapBBl+gJE7SSDZnduO5xgSETpvqDopC8VhjFBoZxuMXNVxxwPwTzrk /jonMA1PEQGQjj6wisW7SKfr+JTJDknA+ZN7NwfSJjvlWessRYtiaOGj8Cwrw9O+IzBo mLqF2Y0H/44ORX8Ya7NOxwP2VQnEzBbTssODgS1D0VK5Y1GoSj1zK+5cG5knhXTmcOFb 3KzdQ3Pd1G8oagCFXE+EiVOVjSmnGImMlAQF4vF7r1AdoTxRjEu4HGt4pdP2RqL2s4Ya fDYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=jG14i4xv6bNS+aKciakq0Caf4sgXzsuaBf2KUiAn4fM=; b=k9PZy3Tb1fogr+aOCq4YFZ8e4eZYzyRFvlgy9w0J+q8E4PuexixxxrN8zUj5wzTaET klDIaYaYWE1/QXQ3AzmevjfyzTi7G+BmnQ5ULu/e1r1AqMbazCgB8ZiZbQFKfb1GUcZs 6uLkQPCU9Wzk04xQEFjKX5ZHsFI3imEL4WkXIOdWdJr3iCL0HH4OP7B9koqPPFYh9BU8 c8pI93EQKmwKbumgPrF9aS97oOtRSkehLl6ZvIVabRtSQ4g/vROc2F5jkx23uoLKOeyz cBOfTCCSqxHJmKZMAXBriHIEm9IYDHcXPMKAf1CUfgkJzZKrRYXoMMg2HMbyuil3gvBW mpNw== X-Gm-Message-State: ANoB5pmZk2tDZRNsLxDhdvVwp3JK+tOjQd0YaqSoRD0otYZcDQiHCdpB 3l5r65QnCEnuY7/tw58xkDm+WrnR/A8= X-Google-Smtp-Source: AA0mqf4IgzwAsywiQhsBEwhmp/aT9x0dpIq8htmpJjifwV7lhFVxWV3m3jWNEmRezhPnZBW+/NY20g== X-Received: by 2002:a05:6808:2389:b0:35a:8ab0:70bf with SMTP id bp9-20020a056808238900b0035a8ab070bfmr3729009oib.77.1667852305081; Mon, 07 Nov 2022 12:18:25 -0800 (PST) Received: from [192.168.88.10] (ip68-11-68-85.no.no.cox.net. [68.11.68.85]) by smtp.googlemail.com with ESMTPSA id e10-20020a4ae0ca000000b004908a9542f8sm1770290oot.31.2022.11.07.12.18.24 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 07 Nov 2022 12:18:24 -0800 (PST) Message-ID: <4240dcf8-2226-15dc-3a0d-1fd76f8c38bc@gmail.com> Date: Mon, 7 Nov 2022 14:18:24 -0600 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.2.2 Subject: Re: Allowing users to create objects in version controlled schema Content-Language: en-US To: pgsql-admin@lists.postgresql.org References: <903563259.260181.1667842135503@office.mailbox.org> From: Ron In-Reply-To: <903563259.260181.1667842135503@office.mailbox.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Why does a developer(?) need to create his own tables in a production(?) database? On 11/7/22 11:28, Erik Wienhold wrote: > I want to get some feedback on the idea of allowing users to create objects in > a database whose schema is already managed with version controlled migrations. > > One of my team mates is displeased with our setup because he cannot create his > own tables without bypassing version control. This is a bad idea IMO even if > it's technically possible to give users a reserved shared namespace that is > never touched by versioned migrations. > > The following issues come to my mind. Issues 1 and 2 are solvable while issues > 3 and 4 are just sources of unnecessary frustration on my part. > > 1. There are multiple users each with a dedicated database user. Consequently, > table owners will vary but those tables should be accessible to any user. > The only solution I can find (besides giving superuser privileges, yikes!) > is to use an event trigger on ddl_command_end to handle CREATE TABLE and > change ownership to a group. > > Is there something like CREATE SCHEMA AUTHORIZATION which applies to objects > created afterwards with separate DDL? Or just leave the owner as it is and > resort to DEFAULT PRIVILEGES instead? > > 2. Users must not create views and procedures that depend on objects managed by > versioned migrations. Otherwise migrations may fail or break procedures > unexpectedly due to untracked dependencies. Event triggers can prevent that > as documented for table rewrites[1]. > > 3. Reinventing the wheel and data duplication if anyone can haphazardly create > new objects. It is also difficult to enforce best practices in that case. > > 4. Harder to reproduce bugs if the complete database schema cannot be recreated > from version control. > > My background is in web applications where you have a nice separation of > database layer and application layer. In our case, users work directly with > a PostGIS-enabled database via QGIS and pgAdmin, hence the "need" (or wish) to > create own tables because it looks like a quick and easy solution to them. > > I still have to accustom to this setup where people directly access the database > instead of having a layer of abstraction in top. > > Has anybody experience with such a setup? More arguments against it are > appreciated. Solutions are also welcome. > > [1] https://www.postgresql.org/docs/15/event-trigger-table-rewrite-example.html > > -- > Erik > > -- Angular momentum makes the world go 'round.