#!/bin/bash
table="$1"
cat <<End
alter table ${table}
    add ${table}Id bigint not null,
    alter ${table}Id position 1;
create generator ${table}Id_gen;
set term ^;
create trigger ${table}_ID for ${table} active before insert position 0 as
begin
    if (new.${table}Id is null) then
        new.${table}Id = gen_id(${table}Id_gen, 1);
end^
set term ;^
set term ^;
create or alter procedure ${table}Id_gen_proc returns (id bigint) as
begin
    select gen_id(${table}Id_gen, 1) from RDB\$DATABASE into :id;
    suspend;
end^
set term ;^
update ${table} set ${table}Id = gen_id(${table}Id_gen, 1);
commit;
alter table ${table}
    add constraint ${table}_pk primary key (${table}Id);
End
