|
@@ -2,21 +2,13 @@ DO $$
|
|
begin
|
|
begin
|
|
|
|
|
|
-- Создаем таблицу званий
|
|
-- Создаем таблицу званий
|
|
-if exists(select from pg_catalog.pg_tables where tablename = 'ranks') then
|
|
|
|
-raise notice 'Ranks table exists';
|
|
|
|
-else
|
|
|
|
-create table ranks (id serial primary key, name varchar(32));
|
|
|
|
-end if;
|
|
|
|
|
|
+create table if not exists ranks (id serial primary key, name varchar(32));
|
|
|
|
|
|
-- Создаем таблицу пользователей
|
|
-- Создаем таблицу пользователей
|
|
-if exists(select from pg_catalog.pg_tables where tablename = 'users') then
|
|
|
|
-raise notice 'Users table exists';
|
|
|
|
-else
|
|
|
|
-create table users (id serial primary key, name varchar(64), rank_id integer references ranks(id));
|
|
|
|
-end if;
|
|
|
|
|
|
+create table if not exists users (id serial primary key, name varchar(64), rank_id integer references ranks(id));
|
|
|
|
|
|
-- Заполняем звания
|
|
-- Заполняем звания
|
|
-if exists(select from ranks where name = 'Рядовой') then
|
|
|
|
|
|
+if exists(select from ranks where name = 'Рядовой' limit 1) then
|
|
raise notice 'Ranks values exist';
|
|
raise notice 'Ranks values exist';
|
|
else
|
|
else
|
|
insert into ranks(name) values ('Рядовой');
|
|
insert into ranks(name) values ('Рядовой');
|
|
@@ -58,19 +50,22 @@ end if;
|
|
|
|
|
|
-- Заполняем тестовые данные:
|
|
-- Заполняем тестовые данные:
|
|
-- -- Пользователь
|
|
-- -- Пользователь
|
|
-if exists(select from users) then
|
|
|
|
|
|
+if exists(select from users limit 1) then
|
|
raise notice 'Test user exists';
|
|
raise notice 'Test user exists';
|
|
else
|
|
else
|
|
insert into users(name, rank_id) values ('Левитан Всеволод Романович', (select id from ranks order by id desc limit 1));
|
|
insert into users(name, rank_id) values ('Левитан Всеволод Романович', (select id from ranks order by id desc limit 1));
|
|
end if;
|
|
end if;
|
|
|
|
+
|
|
|
|
+END $$;
|
|
|
|
+
|
|
|
|
+DO $$
|
|
|
|
+begin
|
|
|
|
+
|
|
-- -- Измерение
|
|
-- -- Измерение
|
|
-if exists(select from measurement_batch) then
|
|
|
|
|
|
+if (select count(id) from measurement_batch limit 1) > 0 then
|
|
raise notice 'Test batch exists';
|
|
raise notice 'Test batch exists';
|
|
else
|
|
else
|
|
insert into measurement_batch(start_period, user_id, pos_x, pos_y) values (now(), (select id from users limit 1), 69.00, 42.00);
|
|
insert into measurement_batch(start_period, user_id, pos_x, pos_y) values (now(), (select id from users limit 1), 69.00, 42.00);
|
|
end if;
|
|
end if;
|
|
|
|
|
|
END$$;
|
|
END$$;
|
|
-
|
|
|
|
--- Проверяем
|
|
|
|
-select batch.id, batch.start_period, concat(rnk.name, ' ', usr.name), batch.pos_x, batch.pos_y from measurement_batch batch join users usr on batch.user_id = usr.id join ranks rnk on usr.rank_id = rnk.id;
|
|
|