From patchwork Mon Mar 27 17:30:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miguel Moreno X-Patchwork-Id: 48756 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 6CD74170E9; Tue, 28 Mar 2023 15:06:46 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, MAILING_LIST_MULTI,SPF_HELO_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 5FE6217061 for ; Tue, 28 Mar 2023 15:06:45 +0100 (BST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ph9yA-0006Lg-3E; Tue, 28 Mar 2023 10:06:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ph3Zn-0003BP-En for guix-patches@gnu.org; Tue, 28 Mar 2023 03:17:03 -0400 Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ph3Zn-0003Sv-74 for guix-patches@gnu.org; Tue, 28 Mar 2023 03:17:03 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1ph3Zn-0002ME-0r for guix-patches@gnu.org; Tue, 28 Mar 2023 03:17:03 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#62495] [PATCH] services: postgresql: Add more role fields. Resent-From: Miguel Moreno Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Tue, 28 Mar 2023 07:17:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 62495 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 62495@debbugs.gnu.org X-Debbugs-Original-To: guix-patches@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.16799878209013 (code B ref -1); Tue, 28 Mar 2023 07:17:02 +0000 Received: (at submit) by debbugs.gnu.org; 28 Mar 2023 07:17:00 +0000 Received: from localhost ([127.0.0.1]:48774 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ph3Zj-0002LC-NL for submit@debbugs.gnu.org; Tue, 28 Mar 2023 03:17:00 -0400 Received: from lists.gnu.org ([209.51.188.17]:37348) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pgqgJ-0005wM-PY for submit@debbugs.gnu.org; Mon, 27 Mar 2023 13:30:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pgqgJ-0004Xi-Gl for guix-patches@gnu.org; Mon, 27 Mar 2023 13:30:55 -0400 Received: from relay2-d.mail.gandi.net ([217.70.183.194]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pgqgG-00011f-Ej for guix-patches@gnu.org; Mon, 27 Mar 2023 13:30:55 -0400 Received: (Authenticated sender: mmoreno@mmoreno.eu) by mail.gandi.net (Postfix) with ESMTPSA id 6E7C640005 for ; Mon, 27 Mar 2023 17:30:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mmoreno.eu; s=gm1; t=1679938247; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type; bh=olxnPa4iPnjkMOewCTtv6KGMdq5Rf2lHGMFBfXGO9FY=; b=JeeGdQWRHiajc32jXh7IFkKfsnwxNM2odttY78uzS796f/BislJ+KfuHZG4QDjBkT2BM0N cMPGRHtu3uAuQp4FVOvzm2HgaC34Xo+4J3jFT5AyY0DMMFsL+ILKJBxs/xb5tOo5tdZeqQ nzF+OQmMbnPpix+cNakzoxf1DX5R1064HOxKSmpIFWRTxj0I6iOmwii8Rt/ct8EyNveaCS ihmo3cxtKhg0MvFobRaZ7THVnxRkjSEcFL/tZIL4oUAahV04QFVto48nXllZ+I9hzC7P5b 5ScUzkBRWXAq7S3gWvn95A9q6p4MoNc0KH8QjHkMXpArO1Hi1JjYZAz2/ebVHQ== From: Miguel Moreno Date: Mon, 27 Mar 2023 19:30:45 +0200 Message-ID: <86tty6rtiy.fsf@mmoreno.eu> User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Received-SPF: pass client-ip=217.70.183.194; envelope-from=mmoreno@mmoreno.eu; helo=relay2-d.mail.gandi.net X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Tue, 28 Mar 2023 03:16:57 -0400 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-Mailman-Approved-At: Tue, 28 Mar 2023 10:06:35 -0400 X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches * gnu/services/databases.scm (postgresql-role): Add more role fields. (postgresql-create-roles): Honor it. * doc/guix.texi (Database Services): Document it. --- doc/guix.texi | 16 +++++++++++++++- gnu/services/databases.scm | 19 ++++++++++++++++--- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/doc/guix.texi b/doc/guix.texi index c49e51b72e..79d6f78e02 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -24635,7 +24635,21 @@ Database Services @code{superuser}. @item @code{create-database?} (default: @code{#f}) -Whether to create a database with the same name as the role. +whether to create a database with the same name as the role. + +@item @code{encoding} (default: @code{"UTF8"}) +The character set to use for storing text in the database. + +@item @code{collation} (default: @code{"en_US.utf8"}) +The string sort order locale setting. + +@item @code{ctype} (default: @code{"en_US.utf8"}) +The character classification locale setting. + +@item @code{template} (default: @code{"template1"}) +The default template to copy the new database from when creating it. +Use @code{"template0"} for a pristine database with no system-local +modifications. @end table @end deftp diff --git a/gnu/services/databases.scm b/gnu/services/databases.scm index b7bd1e587e..9867e4db0c 100644 --- a/gnu/services/databases.scm +++ b/gnu/services/databases.scm @@ -362,7 +362,15 @@ (define-record-type* (permissions postgresql-role-permissions (default '(createdb login))) ;list (create-database? postgresql-role-create-database? ;boolean - (default #f))) + (default #f)) + (encoding postgresql-role-encoding ;string + (default "UTF8")) + (collation postgresql-role-collation ;string + (default "en_US.utf8")) + (ctype postgresql-role-ctype ;string + (default "en_US.utf8")) + (template postgresql-role-template ;string + (default "template1"))) (define-record-type* postgresql-role-configuration make-postgresql-role-configuration @@ -391,7 +399,8 @@ (define (postgresql-create-roles config) (append-map (lambda (role) (match-record role - (name permissions create-database?) + (name permissions create-database? encoding collation ctype + template) `("SELECT NOT(EXISTS(SELECT 1 FROM pg_catalog.pg_roles WHERE \ rolname = '" ,name "')) as not_exists;\n" "\\gset\n" @@ -401,7 +410,11 @@ (define (postgresql-create-roles config) ";\n" ,@(if create-database? `("CREATE DATABASE \"" ,name "\"" - " OWNER \"" ,name "\";\n") + " OWNER \"" ,name "\"\n" + " ENCODING '" ,encoding "'\n" + " LC_COLLATE '" ,collation "'\n" + " LC_CTYPE '" ,ctype "'\n" + " TEMPLATE " ,template ";") '()) "\\endif\n"))) roles)))