javer的表结构设计

news/2024/9/17 16:22:59

javers设计了几张表,这里简单介绍下

jv_snapshot

主要用来存储对象的每次变更操作以及变更的属性值。

-- ----------------------------
--  Table structure for jv_snapshot
-- ----------------------------
DROP TABLE IF EXISTS "public"."jv_snapshot";
CREATE TABLE "public"."jv_snapshot" ("snapshot_pk" int8 NOT NULL,"type" varchar(200) COLLATE "default","version" int8,"state" text COLLATE "default","changed_properties" text COLLATE "default","managed_type" varchar(200) COLLATE "default","global_id_fk" int8,"commit_fk" int8
)
WITH (OIDS=FALSE);
ALTER TABLE "public"."jv_snapshot" OWNER TO "postgres";-- ----------------------------
--  Primary key structure for table jv_snapshot
-- ----------------------------
ALTER TABLE "public"."jv_snapshot" ADD PRIMARY KEY ("snapshot_pk") NOT DEFERRABLE INITIALLY IMMEDIATE;-- ----------------------------
--  Indexes structure for table jv_snapshot
-- ----------------------------
CREATE INDEX  "jv_snapshot_commit_fk_idx" ON "public"."jv_snapshot" USING btree(commit_fk "pg_catalog"."int8_ops" ASC NULLS LAST);
CREATE INDEX  "jv_snapshot_global_id_fk_idx" ON "public"."jv_snapshot" USING btree(global_id_fk "pg_catalog"."int8_ops" ASC NULLS LAST);-- ----------------------------
--  Foreign keys structure for table jv_snapshot
-- ----------------------------
ALTER TABLE "public"."jv_snapshot" ADD CONSTRAINT "jv_snapshot_commit_fk" FOREIGN KEY ("commit_fk") REFERENCES "public"."jv_commit" ("commit_pk") ON UPDATE NO ACTION ON DELETE NO ACTION NOT DEFERRABLE INITIALLY IMMEDIATE;
ALTER TABLE "public"."jv_snapshot" ADD CONSTRAINT "jv_snapshot_global_id_fk" FOREIGN KEY ("global_id_fk") REFERENCES "public"."jv_global_id" ("global_id_pk") ON UPDATE NO ACTION ON DELETE NO ACTION NOT DEFERRABLE INITIALLY IMMEDIATE;

jv_global_id

存储了每次变更的id

-- ----------------------------
--  Table structure for jv_global_id
-- ----------------------------
DROP TABLE IF EXISTS "public"."jv_global_id";
CREATE TABLE "public"."jv_global_id" ("global_id_pk" int8 NOT NULL,"local_id" varchar(200) COLLATE "default","fragment" varchar(200) COLLATE "default","type_name" varchar(200) COLLATE "default","owner_id_fk" int8
)
WITH (OIDS=FALSE);
ALTER TABLE "public"."jv_global_id" OWNER TO "postgres";-- ----------------------------
--  Primary key structure for table jv_global_id
-- ----------------------------
ALTER TABLE "public"."jv_global_id" ADD PRIMARY KEY ("global_id_pk") NOT DEFERRABLE INITIALLY IMMEDIATE;-- ----------------------------
--  Indexes structure for table jv_global_id
-- ----------------------------
CREATE INDEX  "jv_global_id_local_id_idx" ON "public"."jv_global_id" USING btree(local_id COLLATE "default" "pg_catalog"."text_ops" ASC NULLS LAST);-- ----------------------------
--  Foreign keys structure for table jv_global_id
-- ----------------------------
ALTER TABLE "public"."jv_global_id" ADD CONSTRAINT "jv_global_id_owner_id_fk" FOREIGN KEY ("owner_id_fk") REFERENCES "public"."jv_global_id" ("global_id_pk") ON UPDATE NO ACTION ON DELETE NO ACTION NOT DEFERRABLE INITIALLY IMMEDIATE;

jv_commit

存储了每次变更的时间、变更人

-- ----------------------------
--  Table structure for jv_commit
-- ----------------------------
DROP TABLE IF EXISTS "public"."jv_commit";
CREATE TABLE "public"."jv_commit" ("commit_pk" int8 NOT NULL,"author" varchar(200) COLLATE "default","commit_date" timestamp(6) NULL,"commit_id" numeric(22,2)
)
WITH (OIDS=FALSE);
ALTER TABLE "public"."jv_commit" OWNER TO "postgres";-- ----------------------------
--  Primary key structure for table jv_commit
-- ----------------------------
ALTER TABLE "public"."jv_commit" ADD PRIMARY KEY ("commit_pk") NOT DEFERRABLE INITIALLY IMMEDIATE;-- ----------------------------
--  Indexes structure for table jv_commit
-- ----------------------------
CREATE INDEX  "jv_commit_commit_id_idx" ON "public"."jv_commit" USING btree(commit_id "pg_catalog"."numeric_ops" ASC NULLS LAST);

支持自动从SpringSecurity获取auditor

public class SpringSecurityAuthorProvider implements AuthorProvider {public SpringSecurityAuthorProvider() {}public String provide() {Authentication auth = SecurityContextHolder.getContext().getAuthentication();return auth == null?"unauthenticated":auth.getName();}
}

也可以自定义,比如

@Beanpublic AuthorProvider authorProvider() {return new MockAuthorProvider();}

jv_commit_property

用来存储额外的信息,比如存储了用户id,顺带存一下用户名等。

-- ----------------------------
--  Table structure for jv_commit_property
-- ----------------------------
DROP TABLE IF EXISTS "public"."jv_commit_property";
CREATE TABLE "public"."jv_commit_property" ("property_name" varchar(200) NOT NULL COLLATE "default","property_value" varchar(600) COLLATE "default","commit_fk" int8 NOT NULL
)
WITH (OIDS=FALSE);
ALTER TABLE "public"."jv_commit_property" OWNER TO "postgres";-- ----------------------------
--  Primary key structure for table jv_commit_property
-- ----------------------------
ALTER TABLE "public"."jv_commit_property" ADD PRIMARY KEY ("commit_fk", "property_name") NOT DEFERRABLE INITIALLY IMMEDIATE;-- ----------------------------
--  Indexes structure for table jv_commit_property
-- ----------------------------
CREATE INDEX  "jv_commit_property_commit_fk_idx" ON "public"."jv_commit_property" USING btree(commit_fk "pg_catalog"."int8_ops" ASC NULLS LAST);
CREATE INDEX  "jv_commit_property_property_name_property_value_idx" ON "public"."jv_commit_property" USING btree(property_name COLLATE "default" "pg_catalog"."text_ops" ASC NULLS LAST, property_value COLLATE "default" "pg_catalog"."text_ops" ASC NULLS LAST);-- ----------------------------
--  Foreign keys structure for table jv_commit_property
-- ----------------------------
ALTER TABLE "public"."jv_commit_property" ADD CONSTRAINT "jv_commit_property_commit_fk" FOREIGN KEY ("commit_fk") REFERENCES "public"."jv_commit" ("commit_pk") ON UPDATE NO ACTION ON DELETE NO ACTION NOT DEFERRABLE INITIALLY IMMEDIATE;

可以这样自定义

@Beanpublic CommitPropertiesProvider commitPropertiesProvider() {return new CommitPropertiesProvider() {@Overridepublic Map<String, String> provide() {return ImmutableMap.of("key", "ok");}};}

doc

  • javers

http://lihuaxi.xjx100.cn/news/241277.html

相关文章

读书笔记——Python第一个程序Hello world

2019独角兽企业重金招聘Python工程师标准>>> 开始学习python&#xff0c;随手写那么点笔记 ------------------------------------------------------------------------ 我这边使用的是python3.6.0&#xff0c;在cmd下输入python命令&#xff0c;进入python交互环境…

第4.3章

在java中&#xff0c;使用new关键字实例化一个对象时&#xff0c;系统会为该类中的每个成员变量和方法分配内存 每个对象可以用this关键字引用它本身。 如果一个类的方法需要访问该类本身的成员变量或其它方法&#xff0c;就应该使用this引用 java中&#xff0c;每个类属于一个…

java 解压与压缩代码_Java实现多文件压缩和解压缩代码详解

Java实现多文件压缩和解压缩代码import java.io.File;import java.io.FileInputStream;import java.io.FileOutputStream;import java.io.InputStream;import java.io.OutputStream;import java.util.Enumeration;import java.util.zip.ZipEntry;import java.util.zip.ZipFile;…

1030 完美数列(二分解法)

1. 将整型序列从小到大排序后&#xff0c;这道题的本质是&#xff0c;对于每一个元素i&#xff0c;找出最后一个满足p*A[i]>A[j]的元素j&#xff0c;可以转化为找出第一个不满足p*A[i]>A[j]也即p*A[i]<A[j]的元素j。再用j-1。 2.LL product (LL)p*A[i];这里后面两个…

jQuery选择器总结

jQuery的选择器可谓之强大无比&#xff0c;这里简单地总结一下常用的元素查找方法 $("#myELement") 选择id值等于myElement的元素&#xff0c;id值不能重复在文档中只能有一个id值是myElement所以得到的是唯一的元素 $("div") 选择所有的div标签元素&#…

framework7使用笔记

2019独角兽企业重金招聘Python工程师标准>>> myApp.addView(.view-main, {}); 以上这句代码一定要添加 &#xff0c;否则链接的页面不能正常加载 --------------------------------------------- 如果初始化时定义了preprocess&#xff0c;则页面上链接的自动加载将…

1030 完美数列(two pointers解法)

1. 这道题出现在二分法&#xff0c;但是特殊之处在于&#xff0c;双指针是嵌套的&#xff0c;程序看上去有些像暴力枚举&#xff0c;但其实是利用了&#xff0c;如果i<j&#xff0c;a[i]*p>a[j]&#xff0c;那么一定有k在[i,j]范围内&#xff0c;a[i]*p>a[k]&#xff…

Web API 接口-JavaScript全部api接口文档

当使用JavaScript编写网页代码时&#xff0c;有很多API可以使用。以下是所有对象、类型等接口的列表,你在开发网页应用程序或站点时使用它们。 API文档地址&#xff1a;https://developer.mozilla.org/zh-CN/docs/Web/API A ANGLE_instanced_arraysAbstractWorkerAmbientLightS…