Skip to content

Commit

Permalink
Remove the check done at the very beginning of the extension creation…
Browse files Browse the repository at this point in the history
… or upgrade scripts, to be sure the user is a superuser. It is useless as the extension is already defined as "to be managed by a superuser" in its .control file.
  • Loading branch information
beaud76 committed Sep 5, 2020
1 parent 1cdcc66 commit e705a20
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 89 deletions.
4 changes: 1 addition & 3 deletions docs/en/setup.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ The E-Maj extension can now be created into the database, by executing the SQL c

CREATE EXTENSION emaj CASCADE;

To start with, the script verifies that the PostgreSQL version is at least 9.5, and that the current user has the *superuser* attribute.

Then the script creates the *emaj* schema with its technical tables, types and functions.
After having verified that the PostgreSQL version is at least 9.5, the script creates the *emaj* schema and populate it with technical tables, functions and some other objects.

.. caution::

Expand Down
4 changes: 1 addition & 3 deletions docs/fr/setup.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ L'extension E-Maj peut maintenant être créée dans la base de données, en ex

CREATE EXTENSION emaj CASCADE;

Le script commence par vérifier que la version de PostgreSQL est supérieure ou égale à la version 9.5, que le rôle qui exécute le script a bien l'attribut *superuser*.

Le script crée alors le schéma *emaj* avec ses tables techniques, ses types et ses fonctions.
Après avoir vérifié que la version de PostgreSQL est supérieure ou égale à la version 9.5, le script crée le schéma *emaj* avec ses tables techniques, ses fonctions et quelques autres objets.

.. caution::

Expand Down
5 changes: 0 additions & 5 deletions sql/emaj--3.4.0--devel.sql
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,6 @@ $do$
v_emajVersion TEXT;
v_groupList TEXT;
BEGIN
-- check the current role is a superuser
PERFORM 0 FROM pg_roles WHERE rolname = current_user AND rolsuper;
IF NOT FOUND THEN
RAISE EXCEPTION 'E-Maj upgrade: the current user (%) is not a superuser.', current_user;
END IF;
-- the emaj version registered in emaj_param must be '3.4.0'
SELECT param_value_text INTO v_emajVersion FROM emaj.emaj_param WHERE param_key = 'emaj_version';
IF v_emajVersion <> '3.4.0' THEN
Expand Down
9 changes: 0 additions & 9 deletions sql/emaj--devel.sql
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,6 @@
DO LANGUAGE plpgsql
$do$
BEGIN
-- check the current role is a superuser
IF NOT EXISTS
(SELECT 0
FROM pg_catalog.pg_roles
WHERE rolname = current_user
AND rolsuper
) THEN
RAISE EXCEPTION 'E-Maj installation: The current user (%) is not a superuser.', current_user;
END IF;
-- check postgres version is >= 9.5
IF current_setting('server_version_num')::INT < 90500 THEN
RAISE EXCEPTION 'E-Maj installation: The current postgres version (%) is too old for this E-Maj version. It should be at least 9.5.',
Expand Down
9 changes: 0 additions & 9 deletions sql/emaj-devel.sql
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,6 @@
DO LANGUAGE plpgsql
$do$
BEGIN
-- check the current role is a superuser
-- IF NOT EXISTS
-- (SELECT 0
-- FROM pg_catalog.pg_roles
-- WHERE rolname = current_user
-- AND rolsuper
-- ) THEN
-- RAISE EXCEPTION 'E-Maj installation: The current user (%) is not a superuser.', current_user;
-- END IF;
-- check postgres version is >= 9.5
IF current_setting('server_version_num')::INT < 90500 THEN
RAISE EXCEPTION 'E-Maj installation: The current postgres version (%) is too old for this E-Maj version. It should be at least 9.5.',
Expand Down
17 changes: 4 additions & 13 deletions test/11/expected/install_psql.out
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,6 @@ CREATE EXTENSION IF NOT EXISTS btree_gist;
DO LANGUAGE plpgsql
$do$
BEGIN
-- check the current role is a superuser
-- IF NOT EXISTS
-- (SELECT 0
-- FROM pg_catalog.pg_roles
-- WHERE rolname = current_user
-- AND rolsuper
-- ) THEN
-- RAISE EXCEPTION 'E-Maj installation: The current user (%) is not a superuser.', current_user;
-- END IF;
-- check postgres version is >= 9.5
IF current_setting('server_version_num')::INT < 90500 THEN
RAISE EXCEPTION 'E-Maj installation: The current postgres version (%) is too old for this E-Maj version. It should be at least 9.5.',
Expand Down Expand Up @@ -67,12 +58,12 @@ $do$
$do$;
BEGIN TRANSACTION;
DROP SCHEMA IF EXISTS emaj CASCADE;
psql:sql/emaj-devel.sql:62: NOTICE: schema "emaj" does not exist, skipping
psql:sql/emaj-devel.sql:53: NOTICE: schema "emaj" does not exist, skipping
CREATE SCHEMA emaj;
CREATE EXTENSION IF NOT EXISTS dblink;
psql:sql/emaj-devel.sql:65: NOTICE: extension "dblink" already exists, skipping
psql:sql/emaj-devel.sql:56: NOTICE: extension "dblink" already exists, skipping
CREATE EXTENSION IF NOT EXISTS btree_gist;
psql:sql/emaj-devel.sql:66: NOTICE: extension "btree_gist" already exists, skipping
psql:sql/emaj-devel.sql:57: NOTICE: extension "btree_gist" already exists, skipping
COMMENT ON SCHEMA emaj IS
$$Contains all E-Maj related objects.$$;
------------------------------------------------
Expand Down Expand Up @@ -12237,7 +12228,7 @@ $do$
RETURN;
END;
$do$;
psql:sql/emaj-devel.sql:12467: NOTICE: E-Maj installation: E-Maj successfully installed.
psql:sql/emaj-devel.sql:12458: NOTICE: E-Maj installation: E-Maj successfully installed.
COMMIT;
-----------------------------
-- check installation
Expand Down
48 changes: 6 additions & 42 deletions tools/create_sql_install_script.pl
Original file line number Diff line number Diff line change
Expand Up @@ -51,44 +51,8 @@
$status++;
next;
}
# Comment the test on the SUPERUSER role
if ($status == 4) {
if ($line =~ /^ ( IF NOT EXISTS)/) {
print FICOT "--$1\n";
next;
}
if ($line =~ /^ ( \(SELECT 0)/) {
print FICOT "--$1\n";
next;
}
if ($line =~ /^ ( FROM pg_catalog.pg_roles)/) {
print FICOT "--$1\n";
next;
}
if ($line =~ /^ ( WHERE rolname = current_user)/) {
print FICOT "--$1\n";
next;
}
if ($line =~ /^ ( AND rolsuper)/) {
print FICOT "--$1\n";
next;
}
if ($line =~ /^ ( \) THEN)/) {
print FICOT "--$1\n";
next;
}
if ($line =~ /^ ( RAISE EXCEPTION 'E-Maj installation: The current user \(%\) is not a superuser.', current_user;)/) {
print FICOT "--$1\n";
next;
}
if ($line =~ /^ ( END IF;)/) {
print FICOT "--$1\n";
$status++;
next;
}
}
# Add a BEGIN TRANSACTION statement and recreate the emaj schema
if ($status == 5 && $line =~ /^COMMENT ON SCHEMA emaj IS/) {
if ($status == 4 && $line =~ /^COMMENT ON SCHEMA emaj IS/) {
print FICOT "BEGIN TRANSACTION;\n";
print FICOT "\n";
print FICOT "DROP SCHEMA IF EXISTS emaj CASCADE;\n";
Expand All @@ -98,7 +62,7 @@
print FICOT "CREATE EXTENSION IF NOT EXISTS btree_gist;\n";
$status++;
}
if ($status == 6) {
if ($status == 5) {
# Comment the ALTER EXTENSION verbs
if ($line =~ /^ALTER EXTENSION/) {
print FICOT "--$line";
Expand All @@ -115,7 +79,7 @@
}
}
# Comment the calls to the pg_extension_config_dump() function
if ($status == 7) {
if ($status == 6) {
if ($line =~ /^SELECT pg_catalog\.pg_extension_config_dump/) {
print FICOT "--$line";
next;
Expand All @@ -125,13 +89,13 @@
}
}
# Remove the comment setting for internal functions. This curiously fails in Amazon-RDS environment.
if ($status == 8 && $line =~ /^-- Set comments for all internal functions,/) {
if ($status == 7 && $line =~ /^-- Set comments for all internal functions,/) {
for (my $i = 0; $i <= 22; $i++) { $line = <FICIN>; }
$status++;
}

# Add final checks and messages
if ($status == 9 && $line =~ /^-- check the max_prepared_transactions/) {
if ($status == 8 && $line =~ /^-- check the max_prepared_transactions/) {
print FICOT " RAISE NOTICE 'E-Maj installation: E-Maj successfully installed.';\n";
print FICOT "-- check if the role is superuser\n";
print FICOT " PERFORM 0 FROM pg_catalog.pg_roles WHERE rolname = current_user AND rolsuper;\n";
Expand All @@ -147,7 +111,7 @@
# Add a final COMMIT
print FICOT "COMMIT;\n";

if ($status != 10) { die "Error while processing emaj--devel.sql: the status ($status) is expected to be 10."; }
if ($status != 9) { die "Error while processing emaj--devel.sql: the status ($status) is expected to be 9."; }

# Close files
close FICIN;
Expand Down
5 changes: 0 additions & 5 deletions tools/emaj_upgrade.template
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,6 @@ $do$
v_emajVersion TEXT;
v_groupList TEXT;
BEGIN
-- check the current role is a superuser
PERFORM 0 FROM pg_roles WHERE rolname = current_user AND rolsuper;
IF NOT FOUND THEN
RAISE EXCEPTION 'E-Maj upgrade: the current user (%) is not a superuser.', current_user;
END IF;
-- the emaj version registered in emaj_param must be '<PREVIOUS_VERSION>'
SELECT param_value_text INTO v_emajVersion FROM emaj.emaj_param WHERE param_key = 'emaj_version';
IF v_emajVersion <> '<PREVIOUS_VERSION>' THEN
Expand Down

0 comments on commit e705a20

Please sign in to comment.