@@ -1103,6 +1103,74 @@ begin
1103
1103
end;
1104
1104
$outer_migration_block$;
1105
1105
1106
+ -- -----------------------------------------------------------------------------
1107
+ -- 030-add_vectorizer_errors_view.sql
1108
+ do $outer_migration_block$ /* 030-add_vectorizer_errors_view.sql*/
1109
+ declare
1110
+ _sql text ;
1111
+ _migration record;
1112
+ _migration_name text = $migration_name$030 - add_vectorizer_errors_view .sql $migration_name$;
1113
+ _migration_body text =
1114
+ $migration_body$
1115
+ -- rename the ai.vectorizer_errors table to ai._vectorizer_errors
1116
+ alter table ai .vectorizer_errors rename to _vectorizer_errors;
1117
+
1118
+ -- rename the existing index on the ai.vectorizer_error so it follows the right naming convention (adds the _ prefix)
1119
+ -- this is not strictly necessary, but it is a good practice to keep the naming consistent
1120
+ alter index ai .vectorizer_errors_id_recorded_idx rename to _vectorizer_errors_id_recorded_idx;
1121
+
1122
+ -- create a view including vectorizer name
1123
+ create or replace view ai .vectorizer_errors as
1124
+ select
1125
+ ve.* ,
1126
+ v .name
1127
+ from
1128
+ ai ._vectorizer_errors ve
1129
+ left join ai .vectorizer v on ve .id = v .id ;
1130
+
1131
+
1132
+ -- grant privileges on new ai.vectorizer_errors view
1133
+ do language plpgsql $block$
1134
+ declare
1135
+ to_user text ;
1136
+ priv_type text ;
1137
+ with_grant text ;
1138
+ rec record;
1139
+ begin
1140
+ -- find all users that have permissions on old ai.vectorizer_errors table and grant them to the view
1141
+ for rec in
1142
+ select distinct grantee as username, privilege_type, is_grantable
1143
+ from information_schema .role_table_grants
1144
+ where table_schema = ' ai'
1145
+ and table_name = ' _vectorizer_errors'
1146
+ loop
1147
+ to_user := rec .username ;
1148
+ priv_type := rec .privilege_type ;
1149
+ with_grant := ' ' ;
1150
+ if rec .is_grantable then
1151
+ with_grant := ' WITH GRANT OPTION' ;
1152
+ end if;
1153
+ execute format(' GRANT %s ON ai.vectorizer_errors TO %I %s' , priv_type, to_user, with_grant);
1154
+ end loop;
1155
+ end
1156
+ $block$;
1157
+ $migration_body$;
1158
+ begin
1159
+ select * into _migration from ai .pgai_lib_migration where " name" operator(pg_catalog.= ) _migration_name;
1160
+ if _migration is not null then
1161
+ raise notice ' migration %s already applied. skipping.' , _migration_name;
1162
+ if _migration .body operator(pg_catalog.!= ) _migration_body then
1163
+ raise warning ' the contents of migration "%s" have changed' , _migration_name;
1164
+ end if;
1165
+ return;
1166
+ end if;
1167
+ _sql = pg_catalog .format (E' do /*%s*/ $migration_body$\n begin\n %s\n end;\n $migration_body$;' , _migration_name, _migration_body);
1168
+ execute _sql;
1169
+ insert into ai .pgai_lib_migration (" name" , body, applied_at_version)
1170
+ values (_migration_name, _migration_body, $version$__version__$version$);
1171
+ end;
1172
+ $outer_migration_block$;
1173
+
1106
1174
-- ------------------------------------------------------------------------------
1107
1175
-- 001-chunking.sql
1108
1176
@@ -4222,6 +4290,7 @@ begin
4222
4290
if not admin then
4223
4291
execute ' grant usage, create on schema ai to ' || to_user;
4224
4292
execute ' grant select, insert, update, delete on table ai.vectorizer to ' || to_user;
4293
+ execute ' grant select on ai._vectorizer_errors to ' || to_user;
4225
4294
execute ' grant select on ai.vectorizer_errors to ' || to_user;
4226
4295
execute ' grant select on ai.vectorizer_status to ' || to_user;
4227
4296
execute ' grant select, usage on sequence ai.vectorizer_id_seq to ' || to_user;
@@ -4231,6 +4300,7 @@ begin
4231
4300
execute ' grant all privileges on table ai.pgai_lib_version to ' || to_user;
4232
4301
execute ' grant all privileges on table ai.pgai_lib_feature_flag to ' || to_user;
4233
4302
execute ' grant all privileges on table ai.vectorizer to ' || to_user;
4303
+ execute ' grant all privileges on table ai._vectorizer_errors to ' || to_user;
4234
4304
execute ' grant all privileges on table ai.vectorizer_errors to ' || to_user;
4235
4305
execute ' grant all privileges on table ai.vectorizer_status to ' || to_user;
4236
4306
execute ' grant all privileges on sequence ai.vectorizer_id_seq to ' || to_user;
0 commit comments