1
0
Fork 0

Improve code

This commit is contained in:
Alex Kotov 2019-07-23 01:57:17 +05:00
parent be41f79916
commit 2c3f0f5110
Signed by: kotovalexarian
GPG key ID: 553C0EBBEB5D5F08
2 changed files with 45 additions and 45 deletions

View file

@ -31,11 +31,11 @@ class InitialMigration < ActiveRecord::Migration[6.0]
SQL
func :is_good_limited_text, <<~SQL
(str text, min_length integer, max_length integer)
(str text, max_length integer)
RETURNS boolean IMMUTABLE LANGUAGE plpgsql AS
$$
BEGIN
RETURN LENGTH(str) BETWEEN min_length AND max_length AND is_good_text(str);
RETURN LENGTH(str) BETWEEN 1 AND max_length AND is_good_text(str);
END;
$$;
SQL
@ -261,23 +261,23 @@ class InitialMigration < ActiveRecord::Migration[6.0]
SQL
constraint :accounts, :public_name, <<~SQL
public_name IS NULL OR is_good_limited_text(public_name, 1, 255)
public_name IS NULL OR is_good_limited_text(public_name, 255)
SQL
constraint :accounts, :biography, <<~SQL
biography IS NULL OR is_good_limited_text(biography, 1, 10000)
biography IS NULL OR is_good_limited_text(biography, 10000)
SQL
constraint :federal_subjects, :english_name, <<~SQL
is_good_limited_text(english_name, 1, 255)
is_good_limited_text(english_name, 255)
SQL
constraint :federal_subjects, :native_name, <<~SQL
is_good_limited_text(native_name, 1, 255)
is_good_limited_text(native_name, 255)
SQL
constraint :federal_subjects, :centre, <<~SQL
is_good_limited_text(centre, 1, 255)
is_good_limited_text(centre, 255)
SQL
constraint :federal_subjects, :number, <<~SQL
@ -285,63 +285,63 @@ class InitialMigration < ActiveRecord::Migration[6.0]
SQL
constraint :passports, :zip_code, <<~SQL
zip_code IS NULL OR is_good_limited_text(zip_code, 1, 255)
zip_code IS NULL OR is_good_limited_text(zip_code, 255)
SQL
constraint :passports, :town_type, <<~SQL
town_type IS NULL OR is_good_limited_text(town_type, 1, 255)
town_type IS NULL OR is_good_limited_text(town_type, 255)
SQL
constraint :passports, :town_name, <<~SQL
town_name IS NULL OR is_good_limited_text(town_name, 1, 255)
town_name IS NULL OR is_good_limited_text(town_name, 255)
SQL
constraint :passports, :settlement_type, <<~SQL
settlement_type IS NULL OR is_good_limited_text(settlement_type, 1, 255)
settlement_type IS NULL OR is_good_limited_text(settlement_type, 255)
SQL
constraint :passports, :settlement_name, <<~SQL
settlement_name IS NULL OR is_good_limited_text(settlement_name, 1, 255)
settlement_name IS NULL OR is_good_limited_text(settlement_name, 255)
SQL
constraint :passports, :district_type, <<~SQL
district_type IS NULL OR is_good_limited_text(district_type, 1, 255)
district_type IS NULL OR is_good_limited_text(district_type, 255)
SQL
constraint :passports, :district_name, <<~SQL
district_name IS NULL OR is_good_limited_text(district_name, 1, 255)
district_name IS NULL OR is_good_limited_text(district_name, 255)
SQL
constraint :passports, :street_type, <<~SQL
street_type IS NULL OR is_good_limited_text(street_type, 1, 255)
street_type IS NULL OR is_good_limited_text(street_type, 255)
SQL
constraint :passports, :street_name, <<~SQL
street_name IS NULL OR is_good_limited_text(street_name, 1, 255)
street_name IS NULL OR is_good_limited_text(street_name, 255)
SQL
constraint :passports, :residence_type, <<~SQL
residence_type IS NULL OR is_good_limited_text(residence_type, 1, 255)
residence_type IS NULL OR is_good_limited_text(residence_type, 255)
SQL
constraint :passports, :residence_name, <<~SQL
residence_name IS NULL OR is_good_limited_text(residence_name, 1, 255)
residence_name IS NULL OR is_good_limited_text(residence_name, 255)
SQL
constraint :passports, :building_type, <<~SQL
building_type IS NULL OR is_good_limited_text(building_type, 1, 255)
building_type IS NULL OR is_good_limited_text(building_type, 255)
SQL
constraint :passports, :building_name, <<~SQL
building_name IS NULL OR is_good_limited_text(building_name, 1, 255)
building_name IS NULL OR is_good_limited_text(building_name, 255)
SQL
constraint :passports, :apartment_type, <<~SQL
apartment_type IS NULL OR is_good_limited_text(apartment_type, 1, 255)
apartment_type IS NULL OR is_good_limited_text(apartment_type, 255)
SQL
constraint :passports, :apartment_name, <<~SQL
apartment_name IS NULL OR is_good_limited_text(apartment_name, 1, 255)
apartment_name IS NULL OR is_good_limited_text(apartment_name, 255)
SQL
end

View file

@ -70,14 +70,14 @@ CREATE TYPE public.sex AS ENUM (
--
-- Name: is_good_limited_text(text, integer, integer); Type: FUNCTION; Schema: public; Owner: -
-- Name: is_good_limited_text(text, integer); Type: FUNCTION; Schema: public; Owner: -
--
CREATE FUNCTION public.is_good_limited_text(str text, min_length integer, max_length integer) RETURNS boolean
CREATE FUNCTION public.is_good_limited_text(str text, max_length integer) RETURNS boolean
LANGUAGE plpgsql IMMUTABLE
AS $$
BEGIN
RETURN LENGTH(str) BETWEEN min_length AND max_length AND is_good_text(str);
RETURN LENGTH(str) BETWEEN 1 AND max_length AND is_good_text(str);
END;
$$;
@ -174,10 +174,10 @@ CREATE TABLE public.accounts (
biography text,
person_id bigint,
contacts_list_id bigint NOT NULL,
CONSTRAINT biography CHECK (((biography IS NULL) OR public.is_good_limited_text(biography, 1, 10000))),
CONSTRAINT biography CHECK (((biography IS NULL) OR public.is_good_limited_text(biography, 10000))),
CONSTRAINT guest_token CHECK (public.is_guest_token((guest_token)::text)),
CONSTRAINT nickname CHECK (public.is_nickname((nickname)::text)),
CONSTRAINT public_name CHECK (((public_name IS NULL) OR public.is_good_limited_text((public_name)::text, 1, 255)))
CONSTRAINT public_name CHECK (((public_name IS NULL) OR public.is_good_limited_text((public_name)::text, 255)))
);
@ -323,9 +323,9 @@ CREATE TABLE public.federal_subjects (
centre character varying NOT NULL,
number integer NOT NULL,
timezone interval NOT NULL,
CONSTRAINT centre CHECK (public.is_good_limited_text((centre)::text, 1, 255)),
CONSTRAINT english_name CHECK (public.is_good_limited_text((english_name)::text, 1, 255)),
CONSTRAINT native_name CHECK (public.is_good_limited_text((native_name)::text, 1, 255)),
CONSTRAINT centre CHECK (public.is_good_limited_text((centre)::text, 255)),
CONSTRAINT english_name CHECK (public.is_good_limited_text((english_name)::text, 255)),
CONSTRAINT native_name CHECK (public.is_good_limited_text((native_name)::text, 255)),
CONSTRAINT number CHECK ((number > 0))
);
@ -385,21 +385,21 @@ CREATE TABLE public.passports (
building_name character varying,
apartment_type character varying,
apartment_name character varying,
CONSTRAINT apartment_name CHECK (((apartment_name IS NULL) OR public.is_good_limited_text((apartment_name)::text, 1, 255))),
CONSTRAINT apartment_type CHECK (((apartment_type IS NULL) OR public.is_good_limited_text((apartment_type)::text, 1, 255))),
CONSTRAINT building_name CHECK (((building_name IS NULL) OR public.is_good_limited_text((building_name)::text, 1, 255))),
CONSTRAINT building_type CHECK (((building_type IS NULL) OR public.is_good_limited_text((building_type)::text, 1, 255))),
CONSTRAINT district_name CHECK (((district_name IS NULL) OR public.is_good_limited_text((district_name)::text, 1, 255))),
CONSTRAINT district_type CHECK (((district_type IS NULL) OR public.is_good_limited_text((district_type)::text, 1, 255))),
CONSTRAINT residence_name CHECK (((residence_name IS NULL) OR public.is_good_limited_text((residence_name)::text, 1, 255))),
CONSTRAINT residence_type CHECK (((residence_type IS NULL) OR public.is_good_limited_text((residence_type)::text, 1, 255))),
CONSTRAINT settlement_name CHECK (((settlement_name IS NULL) OR public.is_good_limited_text((settlement_name)::text, 1, 255))),
CONSTRAINT settlement_type CHECK (((settlement_type IS NULL) OR public.is_good_limited_text((settlement_type)::text, 1, 255))),
CONSTRAINT street_name CHECK (((street_name IS NULL) OR public.is_good_limited_text((street_name)::text, 1, 255))),
CONSTRAINT street_type CHECK (((street_type IS NULL) OR public.is_good_limited_text((street_type)::text, 1, 255))),
CONSTRAINT town_name CHECK (((town_name IS NULL) OR public.is_good_limited_text((town_name)::text, 1, 255))),
CONSTRAINT town_type CHECK (((town_type IS NULL) OR public.is_good_limited_text((town_type)::text, 1, 255))),
CONSTRAINT zip_code CHECK (((zip_code IS NULL) OR public.is_good_limited_text((zip_code)::text, 1, 255)))
CONSTRAINT apartment_name CHECK (((apartment_name IS NULL) OR public.is_good_limited_text((apartment_name)::text, 255))),
CONSTRAINT apartment_type CHECK (((apartment_type IS NULL) OR public.is_good_limited_text((apartment_type)::text, 255))),
CONSTRAINT building_name CHECK (((building_name IS NULL) OR public.is_good_limited_text((building_name)::text, 255))),
CONSTRAINT building_type CHECK (((building_type IS NULL) OR public.is_good_limited_text((building_type)::text, 255))),
CONSTRAINT district_name CHECK (((district_name IS NULL) OR public.is_good_limited_text((district_name)::text, 255))),
CONSTRAINT district_type CHECK (((district_type IS NULL) OR public.is_good_limited_text((district_type)::text, 255))),
CONSTRAINT residence_name CHECK (((residence_name IS NULL) OR public.is_good_limited_text((residence_name)::text, 255))),
CONSTRAINT residence_type CHECK (((residence_type IS NULL) OR public.is_good_limited_text((residence_type)::text, 255))),
CONSTRAINT settlement_name CHECK (((settlement_name IS NULL) OR public.is_good_limited_text((settlement_name)::text, 255))),
CONSTRAINT settlement_type CHECK (((settlement_type IS NULL) OR public.is_good_limited_text((settlement_type)::text, 255))),
CONSTRAINT street_name CHECK (((street_name IS NULL) OR public.is_good_limited_text((street_name)::text, 255))),
CONSTRAINT street_type CHECK (((street_type IS NULL) OR public.is_good_limited_text((street_type)::text, 255))),
CONSTRAINT town_name CHECK (((town_name IS NULL) OR public.is_good_limited_text((town_name)::text, 255))),
CONSTRAINT town_type CHECK (((town_type IS NULL) OR public.is_good_limited_text((town_type)::text, 255))),
CONSTRAINT zip_code CHECK (((zip_code IS NULL) OR public.is_good_limited_text((zip_code)::text, 255)))
);