Skip to content

Commit

Permalink
perf($MySQL): unify database style
Browse files Browse the repository at this point in the history
`created_by`: varchar(50)
`modified_by`: varchar(50)
`version`: int unsigned, Optimistic locking
`deleted`: enum('N', 'Y')
  • Loading branch information
johnnymillergh committed Mar 4, 2022
1 parent 209e079 commit 67c8967
Show file tree
Hide file tree
Showing 20 changed files with 1,266 additions and 1,291 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
package com.jmsoftware.maf.authcenter.permission.persistence;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.jmsoftware.maf.springcloudstarter.database.BasePersistenceEntity;
import lombok.Data;

import java.time.LocalDateTime;

import static com.baomidou.mybatisplus.annotation.FieldFill.INSERT;
import static com.baomidou.mybatisplus.annotation.FieldFill.UPDATE;
import lombok.EqualsAndHashCode;

/**
* <h1>Permission</h1>
Expand All @@ -19,27 +14,18 @@
* @author Johnny Miller (锺俊), email: johnnysviva@outlook.com, date: 6/27/2021 3:22 PM
*/
@Data
@EqualsAndHashCode(callSuper = true)
@TableName(value = Permission.TABLE_NAME)
public class Permission {
public class Permission extends BasePersistenceEntity {
public static final String TABLE_NAME = "permission";
public static final String COL_ID = "id";
public static final String COL_URL = "url";
public static final String COL_DESCRIPTION = "description";
public static final String COL_TYPE = "type";
public static final String COL_PERMISSION_EXPRESSION = "permission_expression";
public static final String COL_METHOD = "method";
public static final String COL_SORT = "sort";
public static final String COL_PARENT_ID = "parent_id";
public static final String COL_CREATED_BY = "created_by";
public static final String COL_CREATED_TIME = "created_time";
public static final String COL_MODIFIED_BY = "modified_by";
public static final String COL_MODIFIED_TIME = "modified_time";
public static final String COL_DELETED = "deleted";
/**
* Primary key
*/
@TableId(value = COL_ID, type = IdType.AUTO)
private Long id;

/**
* URL. If type of record is page (1), URL stands for route; if type of record is button (2), URL stands for API
*/
Expand Down Expand Up @@ -75,29 +61,4 @@ public class Permission {
*/
@TableField(value = COL_PARENT_ID)
private Long parentId;
/**
* Created by
*/
@TableField(value = COL_CREATED_BY, fill = INSERT)
private Long createdBy;
/**
* Created time
*/
@TableField(value = COL_CREATED_TIME, fill = INSERT)
private LocalDateTime createdTime;
/**
* Modified by
*/
@TableField(value = COL_MODIFIED_BY, fill = UPDATE)
private Long modifiedBy;
/**
* Modified time
*/
@TableField(value = COL_MODIFIED_TIME, fill = UPDATE)
private LocalDateTime modifiedTime;
/**
* Deleted flag
*/
@TableField(value = COL_DELETED, fill = INSERT)
private Byte deleted;
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
package com.jmsoftware.maf.authcenter.role.persistence;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.jmsoftware.maf.springcloudstarter.database.BasePersistenceEntity;
import lombok.Data;

import java.time.LocalDateTime;

import static com.baomidou.mybatisplus.annotation.FieldFill.INSERT;
import static com.baomidou.mybatisplus.annotation.FieldFill.UPDATE;
import lombok.EqualsAndHashCode;

/**
* <h1>Role</h1>
Expand All @@ -19,22 +14,12 @@
* @author Johnny Miller (锺俊), email: johnnysviva@outlook.com, date: 6/27/2021 3:22 PM
*/
@Data
@EqualsAndHashCode(callSuper = true)
@TableName(value = Role.TABLE_NAME)
public class Role {
public class Role extends BasePersistenceEntity {
public static final String TABLE_NAME = "role";
public static final String COL_ID = "id";
public static final String COL_NAME = "name";
public static final String COL_DESCRIPTION = "description";
public static final String COL_CREATED_BY = "created_by";
public static final String COL_CREATED_TIME = "created_time";
public static final String COL_MODIFIED_BY = "modified_by";
public static final String COL_MODIFIED_TIME = "modified_time";
public static final String COL_DELETED = "deleted";
/**
* Primary key
*/
@TableId(value = COL_ID, type = IdType.AUTO)
private Long id;
/**
* Role name
*/
Expand All @@ -45,29 +30,4 @@ public class Role {
*/
@TableField(value = COL_DESCRIPTION)
private String description;
/**
* Created by
*/
@TableField(value = COL_CREATED_BY, fill = INSERT)
private Long createdBy;
/**
* Created time
*/
@TableField(value = COL_CREATED_TIME, fill = INSERT)
private LocalDateTime createdTime;
/**
* Modified by
*/
@TableField(value = COL_MODIFIED_BY, fill = UPDATE)
private Long modifiedBy;
/**
* Modified time
*/
@TableField(value = COL_MODIFIED_TIME, fill = UPDATE)
private LocalDateTime modifiedTime;
/**
* Deleted flag.
*/
@TableField(value = COL_DELETED, fill = INSERT)
private Byte deleted;
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
package com.jmsoftware.maf.authcenter.user.persistence;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.jmsoftware.maf.springcloudstarter.database.BasePersistenceEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.time.LocalDate;
import java.time.LocalDateTime;

import static com.baomidou.mybatisplus.annotation.FieldFill.INSERT;
import static com.baomidou.mybatisplus.annotation.FieldFill.UPDATE;

/**
* <h1>User</h1>
Expand All @@ -20,11 +16,10 @@
* @author Johnny Miller (锺俊), email: johnnysviva@outlook.com, date: 6/27/2021 3:22 PM
*/
@Data
@SuppressWarnings("jol")
@EqualsAndHashCode(callSuper = true)
@TableName(value = User.TABLE_NAME)
public class User {
public class User extends BasePersistenceEntity {
public static final String TABLE_NAME = "user";
public static final String COL_ID = "id";
public static final String COL_USERNAME = "username";
public static final String COL_EMAIL = "email";
public static final String COL_CELLPHONE = "cellphone";
Expand All @@ -34,16 +29,7 @@ public class User {
public static final String COL_GENDER = "gender";
public static final String COL_AVATAR = "avatar";
public static final String COL_STATUS = "status";
public static final String COL_CREATED_BY = "created_by";
public static final String COL_CREATED_TIME = "created_time";
public static final String COL_MODIFIED_BY = "modified_by";
public static final String COL_MODIFIED_TIME = "modified_time";
public static final String COL_DELETED = "deleted";
/**
* Primary key of user
*/
@TableId(value = COL_ID, type = IdType.AUTO)
private Long id;

/**
* Username
*/
Expand Down Expand Up @@ -89,29 +75,4 @@ public class User {
*/
@TableField(value = COL_STATUS)
private Byte status;
/**
* Created by
*/
@TableField(value = COL_CREATED_BY, fill = INSERT)
private Long createdBy;
/**
* Created time
*/
@TableField(value = COL_CREATED_TIME, fill = INSERT)
private LocalDateTime createdTime;
/**
* Modified by
*/
@TableField(value = COL_MODIFIED_BY, fill = UPDATE)
private Long modifiedBy;
/**
* Modified time
*/
@TableField(value = COL_MODIFIED_TIME, fill = UPDATE)
private LocalDateTime modifiedTime;
/**
* Delete flag.
*/
@TableField(value = COL_DELETED, fill = INSERT)
private Byte deleted;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.jmsoftware.maf.common.domain;

import lombok.Getter;
import lombok.ToString;
import lombok.extern.slf4j.Slf4j;

/**
Expand All @@ -10,20 +11,21 @@
*/
@Slf4j
@Getter
@ToString
public enum DeletedField {
/**
* Not deleted
*/
NOT_DELETED((byte) 0, "not deleted"),
NOT_DELETED("N", "not deleted"),
/**
* Deleted
*/
DELETED((byte) 1, "deleted");
DELETED("Y", "deleted");

/**
* The Value.
*/
private final Byte value;
private final String value;
/**
* The Description.
*/
Expand All @@ -35,7 +37,7 @@ public enum DeletedField {
* @param value the value
* @param description the description
*/
DeletedField(Byte value, String description) {
DeletedField(String value, String description) {
this.value = value;
this.description = description;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ mybatis-plus:
global-config:
db-config:
logic-delete-field: deleted
logic-delete-value: "Y"
logic-not-delete-value: "N"
configuration:
map-underscore-to-camel-case: true
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ mybatis-plus:
global-config:
db-config:
logic-delete-field: deleted
logic-delete-value: "Y"
logic-not-delete-value: "N"
configuration:
map-underscore-to-camel-case: true
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ mybatis-plus:
global-config:
db-config:
logic-delete-field: deleted
logic-delete-value: "Y"
logic-not-delete-value: "N"
configuration:
map-underscore-to-camel-case: true
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ mybatis-plus:
global-config:
db-config:
logic-delete-field: deleted
logic-delete-value: "Y"
logic-not-delete-value: "N"
configuration:
map-underscore-to-camel-case: true
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ mybatis-plus:
global-config:
db-config:
logic-delete-field: deleted
logic-delete-value: "Y"
logic-not-delete-value: "N"
configuration:
map-underscore-to-camel-case: true
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
Expand Down
2 changes: 1 addition & 1 deletion docker/configuration/mysql-server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ These files below are MySQL initialization scripts:
```
script
mysql-server-master
1_init_user.sql
1_init_mysql_user.sql
2_mysql_and_fitness_structure_and_data_20210627.sql
```

Expand Down
Loading

0 comments on commit 67c8967

Please sign in to comment.