@opengis/fastify-table 1.2.13 → 1.2.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. package/README.md +86 -86
  2. package/index.js +79 -79
  3. package/package.json +1 -1
  4. package/server/migrations/0.sql +84 -84
  5. package/server/migrations/cls.sql +39 -39
  6. package/server/migrations/properties.sql +184 -184
  7. package/server/migrations/template.sql +34 -34
  8. package/server/migrations/users.sql +175 -175
  9. package/server/plugins/cron/funcs/addCron.js +130 -130
  10. package/server/plugins/cron/index.js +6 -6
  11. package/server/plugins/crud/funcs/dataDelete.js +24 -24
  12. package/server/plugins/crud/funcs/dataInsert.js +53 -53
  13. package/server/plugins/crud/funcs/dataUpdate.js +65 -65
  14. package/server/plugins/crud/funcs/getOpt.js +13 -13
  15. package/server/plugins/crud/funcs/setOpt.js +21 -21
  16. package/server/plugins/crud/funcs/setToken.js +44 -44
  17. package/server/plugins/crud/funcs/utils/getFolder.js +10 -10
  18. package/server/plugins/crud/funcs/utils/logChanges.js +118 -118
  19. package/server/plugins/crud/index.js +23 -23
  20. package/server/plugins/hook/index.js +8 -8
  21. package/server/plugins/logger/errorStatus.js +19 -19
  22. package/server/plugins/logger/index.js +21 -21
  23. package/server/plugins/migration/exec.migrations.js +37 -37
  24. package/server/plugins/migration/index.js +7 -7
  25. package/server/plugins/pg/pgClients.js +21 -21
  26. package/server/plugins/policy/index.js +12 -12
  27. package/server/plugins/policy/sqlInjection.js +33 -33
  28. package/server/plugins/redis/client.js +8 -8
  29. package/server/plugins/redis/funcs/redisClients.js +3 -3
  30. package/server/plugins/redis/index.js +17 -17
  31. package/server/plugins/table/funcs/addTemplateDir.js +8 -8
  32. package/server/plugins/table/funcs/getFilterSQL/index.js +96 -96
  33. package/server/plugins/table/funcs/getFilterSQL/util/formatValue.js +179 -179
  34. package/server/plugins/table/funcs/getFilterSQL/util/getCustomQuery.js +13 -13
  35. package/server/plugins/table/funcs/getFilterSQL/util/getFilterQuery.js +66 -66
  36. package/server/plugins/table/funcs/getFilterSQL/util/getOptimizedQuery.js +12 -12
  37. package/server/plugins/table/funcs/getFilterSQL/util/getTableSql.js +34 -34
  38. package/server/plugins/table/funcs/getTemplates.js +19 -19
  39. package/server/plugins/table/funcs/gisIRColumn.js +82 -82
  40. package/server/plugins/table/funcs/loadTemplate.js +1 -1
  41. package/server/plugins/table/funcs/loadTemplatePath.js +1 -1
  42. package/server/plugins/table/funcs/metaFormat/getSelectVal.js +50 -50
  43. package/server/plugins/table/funcs/metaFormat/index.js +45 -45
  44. package/server/plugins/table/funcs/userTemplateDir.js +1 -1
  45. package/server/plugins/table/index.js +13 -13
  46. package/server/plugins/util/index.js +7 -7
  47. package/server/routes/cron/index.js +14 -14
  48. package/server/routes/crud/controllers/deleteCrud.js +39 -39
  49. package/server/routes/crud/controllers/table.js +91 -91
  50. package/server/routes/logger/controllers/logger.file.js +92 -92
  51. package/server/routes/logger/controllers/utils/checkUserAccess.js +19 -19
  52. package/server/routes/logger/controllers/utils/getRootDir.js +26 -26
  53. package/server/routes/logger/index.js +17 -17
  54. package/server/routes/properties/controllers/properties.add.js +55 -55
  55. package/server/routes/properties/controllers/properties.get.js +17 -17
  56. package/server/routes/properties/index.js +16 -16
  57. package/server/routes/table/controllers/filter.js +67 -67
  58. package/server/routes/table/controllers/form.js +42 -42
  59. package/server/routes/table/controllers/search.js +74 -74
  60. package/server/routes/table/controllers/suggest.js +166 -166
  61. package/server/routes/table/index.js +29 -29
  62. package/server/routes/table/schema.js +64 -64
  63. package/server/routes/util/controllers/status.monitor.js +8 -8
  64. package/server/routes/util/index.js +11 -11
  65. package/utils.js +129 -129
@@ -1,176 +1,176 @@
1
- create schema if not exists admin;
2
-
3
- -- DROP TABLE is exists admin.users;
4
- CREATE TABLE if not exists admin.users();
5
- ALTER TABLE admin.users add column if not exists uid text NOT NULL DEFAULT next_id();
6
- ALTER TABLE admin.users DROP CONSTRAINT if exists admin_user_uid_pkey cascade;
7
- ALTER TABLE admin.users DROP CONSTRAINT if exists user_pk cascade;
8
- ALTER TABLE admin.users DROP CONSTRAINT if exists admin_user_user_rnokpp;
9
-
10
- ALTER TABLE admin.users add column if not exists login text;
11
- ALTER TABLE admin.users add column if not exists password text NOT NULL DEFAULT ''::text;
12
- ALTER TABLE admin.users add column if not exists user_name text;
13
- ALTER TABLE admin.users add column if not exists sur_name text;
14
- ALTER TABLE admin.users add column if not exists father_name text;
15
- ALTER TABLE admin.users add column if not exists email text;
16
- ALTER TABLE admin.users add column if not exists phone text;
17
- ALTER TABLE admin.users add column if not exists avatar text;
18
- ALTER TABLE admin.users add column if not exists enabled boolean;
19
- ALTER TABLE admin.users add column if not exists user_personal_code text;
20
- ALTER TABLE admin.users add column if not exists last_activity_date timestamp without time zone;
21
- ALTER TABLE admin.users add column if not exists user_type text DEFAULT 'regular'::text;
22
- ALTER TABLE admin.users add column if not exists user_rnokpp text;
23
- ALTER TABLE admin.users alter column user_rnokpp drop not null;
24
- ALTER TABLE admin.users add column if not exists social_auth_id text;
25
- ALTER TABLE admin.users add column if not exists social_auth_type text;
26
- ALTER TABLE admin.users add column if not exists salt text;
27
- ALTER TABLE admin.users add column if not exists cdate timestamp without time zone DEFAULT date_trunc('seconds'::text, now());
28
- ALTER TABLE admin.users add column if not exists editor_id text;
29
- ALTER TABLE admin.users add column if not exists editor_date timestamp without time zone;
30
-
31
- ALTER TABLE admin.users add CONSTRAINT admin_user_uid_pkey PRIMARY KEY (uid);
32
- ALTER TABLE admin.users add CONSTRAINT admin_user_user_rnokpp UNIQUE (user_rnokpp);
33
-
34
- COMMENT ON TABLE admin.users IS 'Користувачі';
35
-
36
- COMMENT ON COLUMN admin.users.uid IS 'ID користувача';
37
- COMMENT ON COLUMN admin.users.login IS 'Логін користувача';
38
- COMMENT ON COLUMN admin.users.password IS 'Пароль користувача';
39
- COMMENT ON COLUMN admin.users.user_name IS 'Ім''я користувача';
40
- COMMENT ON COLUMN admin.users.sur_name IS 'Прізвище користувача';
41
- COMMENT ON COLUMN admin.users.father_name IS 'По-батькові користувача';
42
- COMMENT ON COLUMN admin.users.email IS 'Ел. пошта користувача';
43
- COMMENT ON COLUMN admin.users.phone IS 'Номер телефону користувача';
44
- COMMENT ON COLUMN admin.users.avatar IS 'Аватар';
45
- COMMENT ON COLUMN admin.users.enabled IS 'On / Off';
46
- COMMENT ON COLUMN admin.users.last_activity_date IS 'Дата останньої активності';
47
- COMMENT ON COLUMN admin.users.user_type IS 'Тип користувача';
48
- COMMENT ON COLUMN admin.users.salt IS 'Сіль';
49
-
50
- CREATE EXTENSION if not exists pgcrypto SCHEMA public VERSION "1.3";
51
- CREATE OR REPLACE FUNCTION admin.crypt(text, text) RETURNS text AS '$libdir/pgcrypto', 'pg_crypt' LANGUAGE c IMMUTABLE STRICT COST 1;
52
-
53
- -- DROP FUNCTION admin.insert_update_user_before();
54
- CREATE OR REPLACE FUNCTION admin.insert_update_user_before()
55
- RETURNS trigger AS
56
-
57
- $BODY$
58
- DECLARE
59
-
60
- iterations int;
61
- hash character varying;
62
-
63
- BEGIN
64
-
65
- if(TG_OP='INSERT' or (TG_OP='UPDATE' and new.password<>old.password)) then
66
- if(char_length(new.password) <> 0 and char_length(new.password) < 8) then
67
- --raise exception 'password must be longer than 8 characters';
68
- end if;
69
- new.salt=md5(now()::text);
70
- --raise exception '%','change pass';
71
- if(new.salt ='') then
72
- new.salt=gen_salt('md5');
73
- end if;
74
- iterations = 10;
75
- hash='';
76
-
77
- loop
78
- if iterations=0 then
79
- exit;
80
- end if;
81
- hash = md5(new.password||hash||new.salt);
82
- iterations=iterations-1;
83
- end loop;
84
- new.password=admin.crypt(hash,new.salt);
85
-
86
- end if;
87
- RETURN new;
88
- END
89
- $BODY$
90
-
91
- LANGUAGE plpgsql VOLATILE COST 100;
92
-
93
- DROP TRIGGER if exists insert_update_user_before on admin.users;
94
- CREATE TRIGGER insert_update_user_before BEFORE INSERT OR UPDATE ON admin.users FOR EACH ROW
95
- EXECUTE PROCEDURE admin.insert_update_user_before();
96
-
97
- -- DROP TABLE is exists admin.users_social_auth;
98
- CREATE TABLE if not exists admin.users_social_auth();
99
- ALTER TABLE admin.users_social_auth add column if not exists users_social_auth_id text NOT NULL DEFAULT next_id();
100
- ALTER TABLE admin.users_social_auth alter column users_social_auth_id set DEFAULT next_id();
101
- ALTER TABLE admin.users_social_auth DROP CONSTRAINT if exists users_social_auth_pk cascade;
102
- ALTER TABLE admin.users_social_auth DROP CONSTRAINT if exists users_social_auth_users_fk cascade;
103
- ALTER TABLE admin.users_social_auth DROP CONSTRAINT if exists users_social_auth_social_id_email_unique;
104
-
105
- ALTER TABLE admin.users_social_auth add column if not exists uid text not null;
106
- ALTER TABLE admin.users_social_auth add column if not exists user_name text;
107
- ALTER TABLE admin.users_social_auth add column if not exists sur_name text;
108
- ALTER TABLE admin.users_social_auth add column if not exists email text;
109
- ALTER TABLE admin.users_social_auth add column if not exists city text;
110
- ALTER TABLE admin.users_social_auth add column if not exists phone text;
111
- ALTER TABLE admin.users_social_auth add column if not exists social_auth_id text;
112
- ALTER TABLE admin.users_social_auth add column if not exists social_auth_type text;
113
- ALTER TABLE admin.users_social_auth add column if not exists social_auth_code text;
114
- ALTER TABLE admin.users_social_auth add column if not exists social_auth_obj json;
115
- ALTER TABLE admin.users_social_auth add column if not exists social_auth_date timestamp without time zone;
116
- ALTER TABLE admin.users_social_auth add column if not exists social_auth_softpro_code text;
117
- ALTER TABLE admin.users_social_auth add column if not exists enabled boolean;
118
- ALTER TABLE admin.users_social_auth add column if not exists cdate timestamp without time zone;
119
- ALTER TABLE admin.users_social_auth alter column cdate SET DEFAULT date_trunc('seconds'::text, now());
120
-
121
- ALTER TABLE admin.users_social_auth add column if not exists editor_id text;
122
- ALTER TABLE admin.users_social_auth add column if not exists lang text;
123
- ALTER TABLE admin.users_social_auth add column if not exists editor_date timestamp without time zone;
124
- ALTER TABLE admin.users_social_auth add column if not exists social_auth_url text;
125
- ALTER TABLE admin.users_social_auth add CONSTRAINT users_social_auth_pk PRIMARY KEY (users_social_auth_id);
126
- ALTER TABLE admin.users_social_auth add CONSTRAINT users_social_auth_users_fk FOREIGN KEY (uid) REFERENCES admin.users (uid) MATCH SIMPLE on delete cascade;
127
- ALTER TABLE admin.users_social_auth add CONSTRAINT users_social_auth_social_id_email_unique UNIQUE (social_auth_id,email);
128
-
129
- COMMENT ON COLUMN admin.users_social_auth.uid IS 'id пользователя';
130
- COMMENT ON COLUMN admin.users_social_auth.user_name IS 'Имя пользователя';
131
- COMMENT ON COLUMN admin.users_social_auth.sur_name IS 'Фамилия';
132
- COMMENT ON COLUMN admin.users_social_auth.email IS 'email пользователя';
133
- COMMENT ON COLUMN admin.users_social_auth.city IS 'Місто';
134
- COMMENT ON COLUMN admin.users_social_auth.phone IS 'Телефон';
135
- COMMENT ON COLUMN admin.users_social_auth.social_auth_id IS 'ID в соцсети';
136
- COMMENT ON COLUMN admin.users_social_auth.social_auth_type IS 'тип соцсети';
137
- COMMENT ON COLUMN admin.users_social_auth.social_auth_code IS 'код обьекта соцсети, используеться соцсетью';
138
- COMMENT ON COLUMN admin.users_social_auth.social_auth_obj IS 'обьект соцсети';
139
- COMMENT ON COLUMN admin.users_social_auth.social_auth_date IS 'время получение последнего обьекта соцсети';
140
- COMMENT ON COLUMN admin.users_social_auth.social_auth_softpro_code IS 'код обьекта соцсети, создаваемый и используемый сервером авторизации';
141
- COMMENT ON COLUMN admin.users_social_auth.enabled IS 'Выключатель';
142
- COMMENT ON COLUMN admin.users_social_auth.social_auth_url IS 'URL для QR code';
143
-
144
- CREATE TABLE IF NOT EXISTS admin.user_cls();
145
- ALTER TABLE admin.user_cls DROP CONSTRAINT IF EXISTS admin_user_cls_pkey;
146
- ALTER TABLE admin.user_cls DROP CONSTRAINT IF EXISTS admin_user_unique;
147
-
148
- ALTER TABLE admin.user_cls ADD COLUMN IF NOT EXISTS user_clsid text;
149
- ALTER TABLE admin.user_cls ADD COLUMN IF NOT EXISTS code text;
150
- ALTER TABLE admin.user_cls ADD COLUMN IF NOT EXISTS parent text;
151
- ALTER TABLE admin.user_cls ADD COLUMN IF NOT EXISTS name text;
152
- ALTER TABLE admin.user_cls ADD COLUMN IF NOT EXISTS icon text;
153
- ALTER TABLE admin.user_cls ADD COLUMN IF NOT EXISTS data text;
154
- ALTER TABLE admin.user_cls ADD COLUMN IF NOT EXISTS type text;
155
- ALTER TABLE admin.user_cls ADD COLUMN IF NOT EXISTS files json;
156
- ALTER TABLE admin.user_cls ADD COLUMN IF NOT EXISTS cdate timestamp without time zone;
157
- ALTER TABLE admin.user_cls ADD COLUMN IF NOT EXISTS editor_id text;
158
- ALTER TABLE admin.user_cls ADD COLUMN IF NOT EXISTS editor_date timestamp without time zone;
159
- ALTER TABLE admin.user_cls ADD COLUMN IF NOT EXISTS uid text;
160
- ALTER TABLE admin.user_cls ADD COLUMN IF NOT EXISTS color text;
161
-
162
- ALTER TABLE admin.user_cls ALTER COLUMN user_clsid SET NOT NULL;
163
- ALTER TABLE admin.user_cls ALTER COLUMN user_clsid SET DEFAULT next_id();
164
- ALTER TABLE admin.user_cls ALTER COLUMN cdate SET DEFAULT (now())::timestamp without time zone;
165
- ALTER TABLE admin.user_cls ALTER COLUMN uid SET NOT NULL;
166
- ALTER TABLE admin.user_cls ALTER COLUMN uid SET DEFAULT '1'::text;
167
-
168
- ALTER TABLE admin.user_cls ADD CONSTRAINT admin_user_cls_pkey PRIMARY KEY(user_clsid);
169
- ALTER TABLE admin.user_cls ADD CONSTRAINT admin_user_unique UNIQUE(code, parent);
170
-
171
- COMMENT ON TABLE admin.user_cls IS 'Користувацькі класифікатори';
172
- COMMENT ON COLUMN admin.user_cls.user_clsid IS 'ID';
173
- COMMENT ON COLUMN admin.user_cls.code IS 'Код';
174
- COMMENT ON COLUMN admin.user_cls.name IS 'Назва';
175
- COMMENT ON COLUMN admin.user_cls.icon IS 'Іконка';
1
+ create schema if not exists admin;
2
+
3
+ -- DROP TABLE is exists admin.users;
4
+ CREATE TABLE if not exists admin.users();
5
+ ALTER TABLE admin.users add column if not exists uid text NOT NULL DEFAULT next_id();
6
+ ALTER TABLE admin.users DROP CONSTRAINT if exists admin_user_uid_pkey cascade;
7
+ ALTER TABLE admin.users DROP CONSTRAINT if exists user_pk cascade;
8
+ ALTER TABLE admin.users DROP CONSTRAINT if exists admin_user_user_rnokpp;
9
+
10
+ ALTER TABLE admin.users add column if not exists login text;
11
+ ALTER TABLE admin.users add column if not exists password text NOT NULL DEFAULT ''::text;
12
+ ALTER TABLE admin.users add column if not exists user_name text;
13
+ ALTER TABLE admin.users add column if not exists sur_name text;
14
+ ALTER TABLE admin.users add column if not exists father_name text;
15
+ ALTER TABLE admin.users add column if not exists email text;
16
+ ALTER TABLE admin.users add column if not exists phone text;
17
+ ALTER TABLE admin.users add column if not exists avatar text;
18
+ ALTER TABLE admin.users add column if not exists enabled boolean;
19
+ ALTER TABLE admin.users add column if not exists user_personal_code text;
20
+ ALTER TABLE admin.users add column if not exists last_activity_date timestamp without time zone;
21
+ ALTER TABLE admin.users add column if not exists user_type text DEFAULT 'regular'::text;
22
+ ALTER TABLE admin.users add column if not exists user_rnokpp text;
23
+ ALTER TABLE admin.users alter column user_rnokpp drop not null;
24
+ ALTER TABLE admin.users add column if not exists social_auth_id text;
25
+ ALTER TABLE admin.users add column if not exists social_auth_type text;
26
+ ALTER TABLE admin.users add column if not exists salt text;
27
+ ALTER TABLE admin.users add column if not exists cdate timestamp without time zone DEFAULT date_trunc('seconds'::text, now());
28
+ ALTER TABLE admin.users add column if not exists editor_id text;
29
+ ALTER TABLE admin.users add column if not exists editor_date timestamp without time zone;
30
+
31
+ ALTER TABLE admin.users add CONSTRAINT admin_user_uid_pkey PRIMARY KEY (uid);
32
+ ALTER TABLE admin.users add CONSTRAINT admin_user_user_rnokpp UNIQUE (user_rnokpp);
33
+
34
+ COMMENT ON TABLE admin.users IS 'Користувачі';
35
+
36
+ COMMENT ON COLUMN admin.users.uid IS 'ID користувача';
37
+ COMMENT ON COLUMN admin.users.login IS 'Логін користувача';
38
+ COMMENT ON COLUMN admin.users.password IS 'Пароль користувача';
39
+ COMMENT ON COLUMN admin.users.user_name IS 'Ім''я користувача';
40
+ COMMENT ON COLUMN admin.users.sur_name IS 'Прізвище користувача';
41
+ COMMENT ON COLUMN admin.users.father_name IS 'По-батькові користувача';
42
+ COMMENT ON COLUMN admin.users.email IS 'Ел. пошта користувача';
43
+ COMMENT ON COLUMN admin.users.phone IS 'Номер телефону користувача';
44
+ COMMENT ON COLUMN admin.users.avatar IS 'Аватар';
45
+ COMMENT ON COLUMN admin.users.enabled IS 'On / Off';
46
+ COMMENT ON COLUMN admin.users.last_activity_date IS 'Дата останньої активності';
47
+ COMMENT ON COLUMN admin.users.user_type IS 'Тип користувача';
48
+ COMMENT ON COLUMN admin.users.salt IS 'Сіль';
49
+
50
+ CREATE EXTENSION if not exists pgcrypto SCHEMA public VERSION "1.3";
51
+ CREATE OR REPLACE FUNCTION admin.crypt(text, text) RETURNS text AS '$libdir/pgcrypto', 'pg_crypt' LANGUAGE c IMMUTABLE STRICT COST 1;
52
+
53
+ -- DROP FUNCTION admin.insert_update_user_before();
54
+ CREATE OR REPLACE FUNCTION admin.insert_update_user_before()
55
+ RETURNS trigger AS
56
+
57
+ $BODY$
58
+ DECLARE
59
+
60
+ iterations int;
61
+ hash character varying;
62
+
63
+ BEGIN
64
+
65
+ if(TG_OP='INSERT' or (TG_OP='UPDATE' and new.password<>old.password)) then
66
+ if(char_length(new.password) <> 0 and char_length(new.password) < 8) then
67
+ --raise exception 'password must be longer than 8 characters';
68
+ end if;
69
+ new.salt=md5(now()::text);
70
+ --raise exception '%','change pass';
71
+ if(new.salt ='') then
72
+ new.salt=gen_salt('md5');
73
+ end if;
74
+ iterations = 10;
75
+ hash='';
76
+
77
+ loop
78
+ if iterations=0 then
79
+ exit;
80
+ end if;
81
+ hash = md5(new.password||hash||new.salt);
82
+ iterations=iterations-1;
83
+ end loop;
84
+ new.password=admin.crypt(hash,new.salt);
85
+
86
+ end if;
87
+ RETURN new;
88
+ END
89
+ $BODY$
90
+
91
+ LANGUAGE plpgsql VOLATILE COST 100;
92
+
93
+ DROP TRIGGER if exists insert_update_user_before on admin.users;
94
+ CREATE TRIGGER insert_update_user_before BEFORE INSERT OR UPDATE ON admin.users FOR EACH ROW
95
+ EXECUTE PROCEDURE admin.insert_update_user_before();
96
+
97
+ -- DROP TABLE is exists admin.users_social_auth;
98
+ CREATE TABLE if not exists admin.users_social_auth();
99
+ ALTER TABLE admin.users_social_auth add column if not exists users_social_auth_id text NOT NULL DEFAULT next_id();
100
+ ALTER TABLE admin.users_social_auth alter column users_social_auth_id set DEFAULT next_id();
101
+ ALTER TABLE admin.users_social_auth DROP CONSTRAINT if exists users_social_auth_pk cascade;
102
+ ALTER TABLE admin.users_social_auth DROP CONSTRAINT if exists users_social_auth_users_fk cascade;
103
+ ALTER TABLE admin.users_social_auth DROP CONSTRAINT if exists users_social_auth_social_id_email_unique;
104
+
105
+ ALTER TABLE admin.users_social_auth add column if not exists uid text not null;
106
+ ALTER TABLE admin.users_social_auth add column if not exists user_name text;
107
+ ALTER TABLE admin.users_social_auth add column if not exists sur_name text;
108
+ ALTER TABLE admin.users_social_auth add column if not exists email text;
109
+ ALTER TABLE admin.users_social_auth add column if not exists city text;
110
+ ALTER TABLE admin.users_social_auth add column if not exists phone text;
111
+ ALTER TABLE admin.users_social_auth add column if not exists social_auth_id text;
112
+ ALTER TABLE admin.users_social_auth add column if not exists social_auth_type text;
113
+ ALTER TABLE admin.users_social_auth add column if not exists social_auth_code text;
114
+ ALTER TABLE admin.users_social_auth add column if not exists social_auth_obj json;
115
+ ALTER TABLE admin.users_social_auth add column if not exists social_auth_date timestamp without time zone;
116
+ ALTER TABLE admin.users_social_auth add column if not exists social_auth_softpro_code text;
117
+ ALTER TABLE admin.users_social_auth add column if not exists enabled boolean;
118
+ ALTER TABLE admin.users_social_auth add column if not exists cdate timestamp without time zone;
119
+ ALTER TABLE admin.users_social_auth alter column cdate SET DEFAULT date_trunc('seconds'::text, now());
120
+
121
+ ALTER TABLE admin.users_social_auth add column if not exists editor_id text;
122
+ ALTER TABLE admin.users_social_auth add column if not exists lang text;
123
+ ALTER TABLE admin.users_social_auth add column if not exists editor_date timestamp without time zone;
124
+ ALTER TABLE admin.users_social_auth add column if not exists social_auth_url text;
125
+ ALTER TABLE admin.users_social_auth add CONSTRAINT users_social_auth_pk PRIMARY KEY (users_social_auth_id);
126
+ ALTER TABLE admin.users_social_auth add CONSTRAINT users_social_auth_users_fk FOREIGN KEY (uid) REFERENCES admin.users (uid) MATCH SIMPLE on delete cascade;
127
+ ALTER TABLE admin.users_social_auth add CONSTRAINT users_social_auth_social_id_email_unique UNIQUE (social_auth_id,email);
128
+
129
+ COMMENT ON COLUMN admin.users_social_auth.uid IS 'id пользователя';
130
+ COMMENT ON COLUMN admin.users_social_auth.user_name IS 'Имя пользователя';
131
+ COMMENT ON COLUMN admin.users_social_auth.sur_name IS 'Фамилия';
132
+ COMMENT ON COLUMN admin.users_social_auth.email IS 'email пользователя';
133
+ COMMENT ON COLUMN admin.users_social_auth.city IS 'Місто';
134
+ COMMENT ON COLUMN admin.users_social_auth.phone IS 'Телефон';
135
+ COMMENT ON COLUMN admin.users_social_auth.social_auth_id IS 'ID в соцсети';
136
+ COMMENT ON COLUMN admin.users_social_auth.social_auth_type IS 'тип соцсети';
137
+ COMMENT ON COLUMN admin.users_social_auth.social_auth_code IS 'код обьекта соцсети, используеться соцсетью';
138
+ COMMENT ON COLUMN admin.users_social_auth.social_auth_obj IS 'обьект соцсети';
139
+ COMMENT ON COLUMN admin.users_social_auth.social_auth_date IS 'время получение последнего обьекта соцсети';
140
+ COMMENT ON COLUMN admin.users_social_auth.social_auth_softpro_code IS 'код обьекта соцсети, создаваемый и используемый сервером авторизации';
141
+ COMMENT ON COLUMN admin.users_social_auth.enabled IS 'Выключатель';
142
+ COMMENT ON COLUMN admin.users_social_auth.social_auth_url IS 'URL для QR code';
143
+
144
+ CREATE TABLE IF NOT EXISTS admin.user_cls();
145
+ ALTER TABLE admin.user_cls DROP CONSTRAINT IF EXISTS admin_user_cls_pkey;
146
+ ALTER TABLE admin.user_cls DROP CONSTRAINT IF EXISTS admin_user_unique;
147
+
148
+ ALTER TABLE admin.user_cls ADD COLUMN IF NOT EXISTS user_clsid text;
149
+ ALTER TABLE admin.user_cls ADD COLUMN IF NOT EXISTS code text;
150
+ ALTER TABLE admin.user_cls ADD COLUMN IF NOT EXISTS parent text;
151
+ ALTER TABLE admin.user_cls ADD COLUMN IF NOT EXISTS name text;
152
+ ALTER TABLE admin.user_cls ADD COLUMN IF NOT EXISTS icon text;
153
+ ALTER TABLE admin.user_cls ADD COLUMN IF NOT EXISTS data text;
154
+ ALTER TABLE admin.user_cls ADD COLUMN IF NOT EXISTS type text;
155
+ ALTER TABLE admin.user_cls ADD COLUMN IF NOT EXISTS files json;
156
+ ALTER TABLE admin.user_cls ADD COLUMN IF NOT EXISTS cdate timestamp without time zone;
157
+ ALTER TABLE admin.user_cls ADD COLUMN IF NOT EXISTS editor_id text;
158
+ ALTER TABLE admin.user_cls ADD COLUMN IF NOT EXISTS editor_date timestamp without time zone;
159
+ ALTER TABLE admin.user_cls ADD COLUMN IF NOT EXISTS uid text;
160
+ ALTER TABLE admin.user_cls ADD COLUMN IF NOT EXISTS color text;
161
+
162
+ ALTER TABLE admin.user_cls ALTER COLUMN user_clsid SET NOT NULL;
163
+ ALTER TABLE admin.user_cls ALTER COLUMN user_clsid SET DEFAULT next_id();
164
+ ALTER TABLE admin.user_cls ALTER COLUMN cdate SET DEFAULT (now())::timestamp without time zone;
165
+ ALTER TABLE admin.user_cls ALTER COLUMN uid SET NOT NULL;
166
+ ALTER TABLE admin.user_cls ALTER COLUMN uid SET DEFAULT '1'::text;
167
+
168
+ ALTER TABLE admin.user_cls ADD CONSTRAINT admin_user_cls_pkey PRIMARY KEY(user_clsid);
169
+ ALTER TABLE admin.user_cls ADD CONSTRAINT admin_user_unique UNIQUE(code, parent);
170
+
171
+ COMMENT ON TABLE admin.user_cls IS 'Користувацькі класифікатори';
172
+ COMMENT ON COLUMN admin.user_cls.user_clsid IS 'ID';
173
+ COMMENT ON COLUMN admin.user_cls.code IS 'Код';
174
+ COMMENT ON COLUMN admin.user_cls.name IS 'Назва';
175
+ COMMENT ON COLUMN admin.user_cls.icon IS 'Іконка';
176
176
  COMMENT ON COLUMN admin.user_cls.color IS 'Колір';
@@ -1,130 +1,130 @@
1
- import { createHash } from 'crypto';
2
-
3
- import config from '../../../../config.js';
4
- import getRedis from '../../redis/funcs/getRedis.js';
5
- import getPG from '../../pg/funcs/getPG.js';
6
- import logger from '../../logger/getLogger.js';
7
- import cronList from '../cronList.js';
8
-
9
- const md5 = (string) => createHash('md5').update(string).digest('hex');
10
-
11
- const rclient = getRedis();
12
- async function verifyUnique(name) {
13
- const cronId = config.port || 3000 + md5(name);
14
- // one per node check
15
- const key = `cron:unique:${cronId}`;
16
- const unique = await rclient.setnx(key, 1);
17
- const ttl = await rclient.ttl(key);
18
- if (!unique && ttl !== -1) {
19
- return false;
20
- }
21
- await rclient.expire(key, 20);
22
- return true;
23
- }
24
-
25
- const intervalStringMs = {
26
- everyMin: 1000 * 60,
27
- tenMin: 1000 * 60 * 10,
28
- everyHour: 1000 * 60 * 60,
29
- isHalfday: 1000 * 60 * 60 * 12,
30
- dailyHour: 1000 * 60 * 60 * 24,
31
- };
32
-
33
- const interval2ms = {
34
- string: (interval) => {
35
- const date = new Date();
36
- const intervarSplit = interval.match(/^(\*{2}|(\*)?(\d{1,2})):(\*(\d)|(\d{2}))/);
37
- if (!intervarSplit) {
38
- throw new Error(`interval ${interval} not suported`);
39
- }
40
- const [, , isHalfday, dailyHour, , tenMin, HourlyMin] = intervarSplit;
41
- const intervalMs = (isHalfday && intervalStringMs.isHalfday)
42
- || (dailyHour && intervalStringMs.dailyHour)
43
- || (tenMin && intervalStringMs.tenMin)
44
- || intervalStringMs.everyHour;
45
- const offsetDay = ((+dailyHour || 0) * 60 + (+tenMin || +HourlyMin)) * 60 * 1000;
46
- const offsetCur = (date - date.getTimezoneOffset() * 1000 * 60) % intervalMs;
47
- const waitMs = (offsetDay - offsetCur + intervalMs) % intervalMs;
48
- return [waitMs, intervalMs];
49
- },
50
- number: (interval) => {
51
- const date = new Date();
52
- const intervalMs = interval * 1000;
53
- const dateWithTZ = date - date.getTimezoneOffset() * 1000 * 60;
54
- const offsetCur = dateWithTZ % intervalMs;
55
- // start every cron within 1 hour
56
- const sixtyMinutesStartMs = 3600000;
57
- const waitMs = (intervalMs - offsetCur) % sixtyMinutesStartMs;
58
- return [waitMs, intervalMs];
59
- },
60
- };
61
-
62
- async function runCron({
63
- func, name,
64
- }) {
65
- const pg = getPG();
66
-
67
- const unique = await verifyUnique(name);
68
-
69
- if (!unique) return;
70
- const db = pg.options.database;
71
-
72
- try {
73
- // console.log(`cron:${name}`);
74
- const data = await func({ pg });
75
- const subdir = !!data ? 'cron' : 'cron/null';
76
- logger.file(subdir, {
77
- db, name, result: data,
78
- });
79
- }
80
- catch (err) {
81
- logger.file('cron', {
82
- db, name, error: err.toString(),
83
- });
84
- logger.error(err);
85
- }
86
- }
87
-
88
- /**
89
- * interval:
90
- * - 02:54 - every day
91
- * - 2:03 - every day
92
- * - *1:43 - 2 times a day
93
- * - *12:03 - 2 times a day
94
- * - **:54 - every hour
95
- * - **:*3 - every 10 minutes
96
- * - 60 - every minute
97
- * - 10 * 60 - every 10 minutes
98
- */
99
-
100
- export default async function addCron(func, interval) {
101
- const { time = {}, disabled = [] } = config.cron || {};
102
-
103
- const name = func.name || func.toString().split('/').at(-1).split('\'')[0];
104
-
105
- // if (!config.isServer) return;
106
-
107
- if (disabled.includes(name)) {
108
- logger.file('cron', { name, message: 'cron disabled' });
109
- return;
110
- }
111
-
112
- cronList[name] = func;
113
-
114
- const userInterval = time[name] || interval;
115
- const [waitMs, intervalMs] = interval2ms[typeof interval](userInterval);
116
-
117
- if (intervalMs < 1000) {
118
- logger.file('cron', { name, error: `interval ${interval} to small` });
119
- return;
120
- }
121
-
122
- // setTimeout to w8 for the time to start
123
- setTimeout(() => {
124
- runCron({ func, name });
125
- // interval
126
- setInterval(() => {
127
- runCron({ func, name });
128
- }, intervalMs);
129
- }, waitMs);
130
- }
1
+ import { createHash } from 'crypto';
2
+
3
+ import config from '../../../../config.js';
4
+ import getRedis from '../../redis/funcs/getRedis.js';
5
+ import getPG from '../../pg/funcs/getPG.js';
6
+ import logger from '../../logger/getLogger.js';
7
+ import cronList from '../cronList.js';
8
+
9
+ const md5 = (string) => createHash('md5').update(string).digest('hex');
10
+
11
+ const rclient = getRedis();
12
+ async function verifyUnique(name) {
13
+ const cronId = config.port || 3000 + md5(name);
14
+ // one per node check
15
+ const key = `cron:unique:${cronId}`;
16
+ const unique = await rclient.setnx(key, 1);
17
+ const ttl = await rclient.ttl(key);
18
+ if (!unique && ttl !== -1) {
19
+ return false;
20
+ }
21
+ await rclient.expire(key, 20);
22
+ return true;
23
+ }
24
+
25
+ const intervalStringMs = {
26
+ everyMin: 1000 * 60,
27
+ tenMin: 1000 * 60 * 10,
28
+ everyHour: 1000 * 60 * 60,
29
+ isHalfday: 1000 * 60 * 60 * 12,
30
+ dailyHour: 1000 * 60 * 60 * 24,
31
+ };
32
+
33
+ const interval2ms = {
34
+ string: (interval) => {
35
+ const date = new Date();
36
+ const intervarSplit = interval.match(/^(\*{2}|(\*)?(\d{1,2})):(\*(\d)|(\d{2}))/);
37
+ if (!intervarSplit) {
38
+ throw new Error(`interval ${interval} not suported`);
39
+ }
40
+ const [, , isHalfday, dailyHour, , tenMin, HourlyMin] = intervarSplit;
41
+ const intervalMs = (isHalfday && intervalStringMs.isHalfday)
42
+ || (dailyHour && intervalStringMs.dailyHour)
43
+ || (tenMin && intervalStringMs.tenMin)
44
+ || intervalStringMs.everyHour;
45
+ const offsetDay = ((+dailyHour || 0) * 60 + (+tenMin || +HourlyMin)) * 60 * 1000;
46
+ const offsetCur = (date - date.getTimezoneOffset() * 1000 * 60) % intervalMs;
47
+ const waitMs = (offsetDay - offsetCur + intervalMs) % intervalMs;
48
+ return [waitMs, intervalMs];
49
+ },
50
+ number: (interval) => {
51
+ const date = new Date();
52
+ const intervalMs = interval * 1000;
53
+ const dateWithTZ = date - date.getTimezoneOffset() * 1000 * 60;
54
+ const offsetCur = dateWithTZ % intervalMs;
55
+ // start every cron within 1 hour
56
+ const sixtyMinutesStartMs = 3600000;
57
+ const waitMs = (intervalMs - offsetCur) % sixtyMinutesStartMs;
58
+ return [waitMs, intervalMs];
59
+ },
60
+ };
61
+
62
+ async function runCron({
63
+ func, name,
64
+ }) {
65
+ const pg = getPG();
66
+
67
+ const unique = await verifyUnique(name);
68
+
69
+ if (!unique) return;
70
+ const db = pg.options.database;
71
+
72
+ try {
73
+ // console.log(`cron:${name}`);
74
+ const data = await func({ pg });
75
+ const subdir = !!data ? 'cron' : 'cron/null';
76
+ logger.file(subdir, {
77
+ db, name, result: data,
78
+ });
79
+ }
80
+ catch (err) {
81
+ logger.file('cron', {
82
+ db, name, error: err.toString(),
83
+ });
84
+ logger.error(err);
85
+ }
86
+ }
87
+
88
+ /**
89
+ * interval:
90
+ * - 02:54 - every day
91
+ * - 2:03 - every day
92
+ * - *1:43 - 2 times a day
93
+ * - *12:03 - 2 times a day
94
+ * - **:54 - every hour
95
+ * - **:*3 - every 10 minutes
96
+ * - 60 - every minute
97
+ * - 10 * 60 - every 10 minutes
98
+ */
99
+
100
+ export default async function addCron(func, interval) {
101
+ const { time = {}, disabled = [] } = config.cron || {};
102
+
103
+ const name = func.name || func.toString().split('/').at(-1).split('\'')[0];
104
+
105
+ // if (!config.isServer) return;
106
+
107
+ if (disabled.includes(name)) {
108
+ logger.file('cron', { name, message: 'cron disabled' });
109
+ return;
110
+ }
111
+
112
+ cronList[name] = func;
113
+
114
+ const userInterval = time[name] || interval;
115
+ const [waitMs, intervalMs] = interval2ms[typeof interval](userInterval);
116
+
117
+ if (intervalMs < 1000) {
118
+ logger.file('cron', { name, error: `interval ${interval} to small` });
119
+ return;
120
+ }
121
+
122
+ // setTimeout to w8 for the time to start
123
+ setTimeout(() => {
124
+ runCron({ func, name });
125
+ // interval
126
+ setInterval(() => {
127
+ runCron({ func, name });
128
+ }, intervalMs);
129
+ }, waitMs);
130
+ }
@@ -1,6 +1,6 @@
1
- import addCron from './funcs/addCron.js';
2
-
3
- async function plugin(fastify) {
4
- // fastify.decorate('addCron', addCron);
5
- }
6
- export default plugin;
1
+ import addCron from './funcs/addCron.js';
2
+
3
+ async function plugin(fastify) {
4
+ // fastify.decorate('addCron', addCron);
5
+ }
6
+ export default plugin;