Инструменты пользователя

Инструменты сайта


lss-server-php:db-datastructure-sqlite

Это старая версия документа!


SQlite - требования к структуре БД

Создание и инициализация системных таблиц

Для корректной работы LSS сервера в базе данных должны присутствовать системные таблицы:

  • systablecategory, systable, sysfield, sysfieldparams, sysconstraint - таблицы для хранения и правки LSS описания БД.
  • sysfieldtype - справочник допустимых для LSS типов данных
  • sysextlog - лог успешности выполнения плановых работ по обслуживанию системы
  • sysdblog - лог для хранения истории правки пользовательских данных
  • syssession, syssessioninfo - таблицы для хранения пользовательских данных, привязанных к сессии пользователя.
  • sysconfig - таблица для хранения и правки системных настроечных констант, привязанных к площадке сервера.

Для их создания и корректной начальной инициализации служат скрипты sqlite-systable-create.sql и sqlite-systable-init.sql, расположенные в папке /sql/init/sqlite шаблона LSS проекта.

Эти скрипты необходимо последовательно прогнать на пустой БД.

содержимое скрипта создания системных таблиц

-- Создание системных таблиц для сервера PostgreSql, для инициализации служит скрипт systable-init.sql

-- Типы полей
create table "sysfieldtype" (
	"id" bigserial primary key,
	"name" varchar(255) not null default '',
	"isid" boolean not null default '0',
	"isref" boolean not null default '0',
	"isdec" boolean not null default '0',
	"isstr" boolean not null default '0',
	"isdat" boolean not null default '0',
	"defvalue" varchar(255) not null default '',
	"jstype" varchar(255) not null default '',
	"lsstype" varchar(255) not null default '',
	"ord" bigint not null default 0
);

-- Категории таблиц
create table "systablecategory" (
	"id" bigserial primary key,
	"name" varchar(255) not null default '',
	"ord" bigint not null default 0
);

-- Таблицы
create table "systable" (
	"id" bigserial primary key,
	"klssystablecategory" bigint references "systablecategory" on delete cascade deferrable initially deferred,
	"tablename" varchar(255) not null default '',
	"name" varchar(255) not null default '',
	"info" text not null default '',
	"orderby" text not null default '',
	"sqlview" text not null default '',
	"permmode" varchar(255) not null default '',
	"log" varchar(32) not null default '',
	"isstatic" boolean not null default '0',
	"isdynamic" boolean not null default '0',
	"issystem" boolean not null default '0',
	"tabletype" varchar(32) not null default ''
);
create index "idx_systable_klssystablecategory" on "systable" ("klssystablecategory");

-- Поля
create table "sysfield" (
	"id" bigserial primary key,
	"klssystable" bigint references "systable" on delete cascade deferrable initially deferred,
	"fieldname" varchar(255) not null default '',
	"name" varchar(255) not null default '',
	"info" text not null default '',
	"klssysfieldtype" bigint references "sysfieldtype" deferrable initially deferred,
	"isnotempty" boolean not null default '0',
	"ismain" boolean not null default '0',
	"maxlength" integer not null default 0,
	"len" integer not null default 0,
	"dec" integer not null default 0,
	"isstretch" boolean not null default '0',
	"klsreftable" bigint references "systable" deferrable initially deferred,
	"reflink" varchar(255) not null default '',
	"isrefrestrict" boolean not null default '0',
	"isrefcascade" boolean not null default '0',
	"isrefclear" boolean not null default '0',
	"isref121" boolean not null default '0',
	"islog" boolean not null default '0',
	"isvirtual" boolean not null default '0',
	"ord" bigint not null default 0
);
create index "idx_sysfield_klssystable" on "sysfield" ("klssystable");
create index "idx_sysfield_klssysfieldtype" on "sysfield" ("klssysfieldtype");
create index "idx_sysfield_klsreftable" on "sysfield" ("klsreftable");

-- Параметры полей
create table "sysfieldparams" (
	"id" bigserial primary key,
	"klssysfield" bigint references "sysfield" on delete cascade deferrable initially deferred,
	"name" varchar(255) not null default '',
	"val" text not null default ''
);
create index "idx_sysfieldparams_klssysfield" on "sysfieldparams" ("klssysfield");

-- Ограничения, для руссификации сообщений об ошибках
create table "sysconstraint" (
	"id" bigserial primary key,
	"klssystable" bigint references "systable" on delete cascade deferrable initially deferred,
	"constraintname" varchar(255) not null default '',
	"message" text not null default ''
);
create index "idx_sysconstraint_klssystable" on "sysconstraint" ("klssystable");

-- Системный лог фоновых процессов
create table "sysextlog" (
	"id" bigserial primary key,
	"d" date,
	"tstart" varchar(5) not null default '',
	"tend" varchar(5) not null default '',
	"name" varchar(64) not null default '',
	"message" text not null default '',
	"iserror" int not null default '0'
);

-- История правки данных
create table "sysdblog" (
	"id" bigserial primary key,
	"child" varchar(36) not null default '',
	"childid" varchar(36) not null default '',
	"table" varchar(36) not null default '',
	"field" varchar(36) not null default '',
	"rowid" varchar(36) not null default '',
	"operation" varchar(3) not null default '',
	"value" varchar(1024) not null default '',
	"user" varchar(36) not null default '',
	"d" date,
	"t" varchar(8) not null default ''
);
create index "idx_sysdblog_child" on "sysdblog" ("child","childid");
create index "idx_sysdblog_table" on "sysdblog" ("table","rowid");
create index "idx_sysdblog_user" on "sysdblog" ("user");
create index "idx_sysdblog_d" on "sysdblog" ("d");

-- Хранение основных данных сессии в БД
create table "syssession" (
	"id" bigserial primary key,
	"code" varchar(128) not null,
	"value" text not null default '',
	"dcreate" timestamp not null default now(),
	"dlast" timestamp not null default now()
);
create index "idx_syssession_code" on "syssession" ("code");
create index "idx_syssession_dlast" on "syssession" ("dlast");

-- Хранение дополнительных данных сессии в БД
create table "syssessioninfo" (
	"id" bigserial primary key,
	"syssessionid" bigint references "syssession" on delete cascade deferrable initially deferred,
	"code" varchar(64) not null default '',
	"value" text not null default '',
	"params" text not null default '',
	"dcreate" timestamp not null default now(),
	"json" jsonb
);
create index "idx_syssessioninfo_syssessionid" on "syssessioninfo" ("syssessionid","code");

-- Системные конфигурации площадки
create table "sysconfig" (
	"id" bigserial primary key,
	"code" varchar(32) not null default '',
	"val" varchar(64) not null default ''
);
alter table "sysconfig" add unique("code") deferrable initially deferred;

-- Системный лог выполнения версион скриптов
create table "sysdbversion" (
	"id" serial primary key,
	"code" varchar(64) not null default ''
);
create unique index "uidx_sysdbversion_code" on "sysdbversion" ("code");

-- автоинкрементный генератор для 
create sequence sysappend_id_seq AS bigint;
select setval('sysappend_id_seq', 100000);

-- хранимая процедура удаления view
-- вызов call cmd_dropviews('user') - удалить все view, использующие таблицу user
-- вызов call cmd_dropviews() - удалить все view
create or replace procedure cmd_dropviews(tablename varchar(255) default '')
language plpgsql
as $$
declare
	rec record;
	cmd varchar(1024);
begin
	if tablename='' then
		for rec in
			select distinct view_name
			from
				information_schema.view_table_usage
			where
				view_schema='public' and
				table_schema='public' and
				substring(view_name,1,5)='view_'
		loop
			cmd=concat('drop view "',rec.view_name,'"');
			raise info '%', cmd;
			execute cmd;
		end loop;
	else
		for rec in
			select distinct view_name
			from
				information_schema.view_table_usage
			where
				view_schema='public' and
				table_schema='public' and
				table_name=tablename and
				substring(view_name,1,5)='view_'
		loop
			cmd=concat('drop view "',rec.view_name,'"');
			raise info '%', cmd;
			execute cmd;
		end loop;
	end if;
end;
$$;
lss-server-php/db-datastructure-sqlite.1781528740.txt.gz · Последнее изменение: 2026/06/15 16:05 — madmin

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki