create table t_restful_api
(
	id serial not null,
	"table" varchar(255) not null,
	fields varchar(255) not null,
	conditions text not null,
	name varchar(255) not null,
	method varchar(10) not null,
	url varchar(255) not null,
	enabled boolean not null
);

comment on table t_restful_api is 'REST服务';

comment on column t_restful_api.id is 'ID唯一标识';

comment on column t_restful_api."table" is '数据库表名称';

comment on column t_restful_api.fields is '数据库表字段';

comment on column t_restful_api.conditions is '数据库表查询条件';

comment on column t_restful_api.name is '接口名称';

comment on column t_restful_api.method is '请求方法';

comment on column t_restful_api.url is '接口路由';

comment on column t_restful_api.enabled is '是否已启用';

create unique index t_restful_api_id_uindex
	on t_restful_api (id);

alter table t_restful_api
	add constraint t_restful_api_pk
		primary key (id);





create table t_restful_api_record
(
	id serial not null,
	rest_service_id int not null,
	visit_time timestamp not null,
	token varchar(255) not null
);

comment on table t_restful_api_record is 'REST服务访问记录';

comment on column t_restful_api_record.rest_service_id is 'rest服务id';

comment on column t_restful_api_record.visit_time is '访问时间';

comment on column t_restful_api_record.token is '令牌';

create unique index t_restful_api_record_id_uindex
	on t_restful_api_record (id);

alter table t_restful_api_record
	add constraint t_restful_api_record_pk
		primary key (id);





alter table t_resource_consumption
	add rest_service_id int;

comment on column t_resource_consumption.rest_service_id is 'rest服务id';
