From patchwork Tue Jun 6 09:28:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Miguel_=C3=81ngel_Moreno?= X-Patchwork-Id: 50734 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 C99EB27BBEA; Tue, 6 Jun 2023 14:50:31 +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=-2.7 required=5.0 tests=BAYES_00,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 E424927BBE2 for ; Tue, 6 Jun 2023 14:50:30 +0100 (BST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q6X4m-0005J5-KA; Tue, 06 Jun 2023 09:50:21 -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 1q6X4W-000571-Kj for guix-patches@gnu.org; Tue, 06 Jun 2023 09:50:06 -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 1q6X4V-0000nb-6p for guix-patches@gnu.org; Tue, 06 Jun 2023 09:50:04 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1q6X4U-0001ap-TV for guix-patches@gnu.org; Tue, 06 Jun 2023 09:50:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#63926] [PATCH] services: postgresql: Add more role fields. Resent-From: Miguel =?utf-8?b?w4FuZ2Vs?= Moreno Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Tue, 06 Jun 2023 13:50:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 63926 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 63926@debbugs.gnu.org Cc: me@mianmoreno.com X-Debbugs-Original-To: guix-patches@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.16860593936072 (code B ref -1); Tue, 06 Jun 2023 13:50:02 +0000 Received: (at submit) by debbugs.gnu.org; 6 Jun 2023 13:49:53 +0000 Received: from localhost ([127.0.0.1]:51231 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1q6X4K-0001Zm-AF for submit@debbugs.gnu.org; Tue, 06 Jun 2023 09:49:52 -0400 Received: from lists.gnu.org ([209.51.188.17]:47854) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1q6SzZ-0006xt-8Q for submit@debbugs.gnu.org; Tue, 06 Jun 2023 05:28:42 -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 1q6SzZ-0004kO-2E for guix-patches@gnu.org; Tue, 06 Jun 2023 05:28:41 -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 1q6SzX-0006Wh-9o for guix-patches@gnu.org; Tue, 06 Jun 2023 05:28:40 -0400 X-GND-Sasl: me@mianmoreno.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mianmoreno.com; s=gm1; t=1686043717; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=D5t8CXyoCjk7qAwTrY/4JaJY5oNibLod+NyBX27gmls=; b=bzeSQo3Gk187DT8TIQ1h/cEiPv81wO7ihavPUT1lJkb8ONiAgey5X/jwDfySAAZvtNjyg9 Zc3827MYBNtl3iM2VFh6JJA18vNGOJjzyLMfrpG9Kcnr77PKcvRjSIOOryAsUc2brQnmho w0rGD1MWIPsngfeblqay3IRmN+LGxsDl06QKfsbayE1XP/44grFCOd8kUJIf5MvZHavzON bjH9x7VZTL54lZH5MmOJYcIHZE4mzlf4fRB6S4gE0y4FHVGTjSmIFDogHZLiTfZST0UU+S vbvEwg7N8h70VfwKN/XkcZKEV5OzkieXufViK3zT+dNuRH1zT/Dfl6hPIM1hhQ== X-GND-Sasl: me@mianmoreno.com Received: by mail.gandi.net (Postfix) with ESMTPSA id 7624E40015; Tue, 6 Jun 2023 09:28:35 +0000 (UTC) From: Miguel =?utf-8?b?w4FuZ2Vs?= Moreno Date: Tue, 06 Jun 2023 11:28:35 +0200 Message-ID: <86legxos70.fsf@mianmoreno.com> User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Received-SPF: pass client-ip=217.70.183.194; envelope-from=me@mianmoreno.com; 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.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Tue, 06 Jun 2023 09:49:41 -0400 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list 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 60972f408d..e384a3a13d 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -24784,7 +24784,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 e8e42d3b7b..7148971c1d 100644 --- a/gnu/services/databases.scm +++ b/gnu/services/databases.scm @@ -363,7 +363,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 @@ -392,7 +400,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" @@ -402,7 +411,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)))