Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove fill_ident_country postgresql function as unused #1439

Merged
merged 1 commit into from
Dec 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class RemoveFillIdentCountryFunction < ActiveRecord::Migration[5.0]
def change
execute <<~SQL
DROP FUNCTION fill_ident_country();
SQL
end
end
103 changes: 2 additions & 101 deletions db/structure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -66,106 +66,6 @@ CREATE EXTENSION IF NOT EXISTS pgcrypto WITH SCHEMA public;
COMMENT ON EXTENSION pgcrypto IS 'cryptographic functions';


--
-- Name: fill_ident_country(); Type: FUNCTION; Schema: public; Owner: -
--

CREATE FUNCTION public.fill_ident_country() RETURNS boolean
LANGUAGE plpgsql
AS $_$
DECLARE
changed BOOLEAN;
multiplier INT [];
multiplier2 INT [];
multiplier3 INT [];
multiplier4 INT [];
r RECORD;
control TEXT;
total INT;
i INT;
mod INT;
counter INT;
BEGIN

multiplier := ARRAY [1, 2, 3, 4, 5, 6, 7, 8, 9, 1];
multiplier2 := ARRAY [3, 4, 5, 6, 7, 8, 9, 1, 2, 3];
multiplier3 := ARRAY [1, 2, 3, 4, 5, 6, 7];
multiplier4 := ARRAY [3, 4, 5, 6, 7, 8, 9];

FOR r IN SELECT id, ident FROM contacts WHERE ident_type = 'priv' AND ident_country_code IS NULL
LOOP
IF (length(r.ident) = 11 AND (r.ident ~ '^[0-9]+$') AND (substring(r.ident, 1, 1) = '3' OR substring(r.ident, 1, 1) = '4' OR substring(r.ident, 1, 1) = '5' OR substring(r.ident, 1, 1) = '6'))
THEN
total := 0;
counter := 1;
FOREACH i IN ARRAY multiplier
LOOP
total := (total + (i * to_number(substring(r.ident, counter, 1), '9')));
counter := (counter + 1);
END LOOP;
mod := (total % 11);
counter := 1;
IF (mod >= 10)
THEN
total = 0;
FOREACH i IN ARRAY multiplier2
LOOP
total := (total + (i * to_number(substring(r.ident, counter, 1), '9')));
counter := (counter + 1);
END LOOP;
mod := (total % 11);
END IF;
IF (mod = 10)
THEN
mod := 0;
END IF;
IF (substring(r.ident, 11, 1) = to_char(mod, 'FM999MI'))
THEN
UPDATE contacts SET ident_country_code = 'EE' WHERE id = r.id;
END IF;
total := 0;
END IF;
END LOOP;

FOR r IN SELECT id, ident FROM contacts WHERE ident_type = 'org' AND ident_country_code IS NULL
LOOP
IF (length(r.ident) = 8 AND (r.ident ~ '^[0-9]+$') AND (substring(r.ident, 1, 1) = '1' OR substring(r.ident, 1, 1) = '8' OR substring(r.ident, 1, 1) = '9'))
THEN
total := 0;
counter := 1;
FOREACH i IN ARRAY multiplier3
LOOP
total := (total + (i * to_number(substring(r.ident, counter, 1), '9')));
counter := (counter + 1);
END LOOP;
mod := total % 11;
total := 0;
counter := 1;
IF (mod >= 10)
THEN
total = 0;
FOREACH i IN ARRAY multiplier4
LOOP
total := (total + (i * to_number(substring(r.ident, counter, 1), '9')));
counter := (counter + 1);
END LOOP;
mod := (total % 11);
END IF;
IF (mod = 10)
THEN
mod := 0;
END IF;
IF (substring(r.ident, 8, 1) = to_char(mod, 'FM999MI'))
THEN
UPDATE contacts SET ident_country_code = 'EE' WHERE id = r.id;
END IF;
END IF;
END LOOP;
RETURN changed;
END;
$_$;


--
-- Name: generate_zonefile(character varying); Type: FUNCTION; Schema: public; Owner: -
--
Expand Down Expand Up @@ -4362,6 +4262,7 @@ INSERT INTO "schema_migrations" (version) VALUES
('20191008024334'),
('20191024153351'),
('20191024160038'),
('20191206183853');
('20191206183853'),
('20191212133136');