diff --git a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/Audit.java b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/Audit.java index 3466d58ef3f..e82a4501184 100644 --- a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/Audit.java +++ b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/Audit.java @@ -7,28 +7,30 @@ import javax.persistence.Column; import javax.persistence.Entity; +import javax.persistence.SequenceGenerator; import javax.persistence.Table; @Entity -@Table(name = "Audit") -@SQLDelete(sql = "Update Audit set isDeleted = 1 where id = ?") -@Where(clause = "isDeleted = 0") +@Table(name = "audit") +@SQLDelete(sql = "UPDATE audit SET deleted = TRUE WHERE id = ?") +@Where(clause = "NOT deleted") +@SequenceGenerator(name = "sequence", sequenceName = "audit_id_seq", allocationSize = 1) public class Audit extends BaseEntity { public enum OP { INSERT, UPDATE, DELETE } - @Column(name = "EntityName", nullable = false) + @Column(name = "entity_name", nullable = false) private String entityName; - @Column(name = "EntityId") + @Column(name = "entity_id") private Long entityId; - @Column(name = "OpName", nullable = false) + @Column(name = "op_name", nullable = false) private String opName; - @Column(name = "Comment") + @Column(name = "comment") private String comment; public String getComment() { diff --git a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/Cluster.java b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/Cluster.java index 3051ed3dec5..8a087355b96 100644 --- a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/Cluster.java +++ b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/Cluster.java @@ -7,24 +7,26 @@ import javax.persistence.Column; import javax.persistence.Entity; +import javax.persistence.SequenceGenerator; import javax.persistence.Table; /** * @author Jason Song(song_s@ctrip.com) */ @Entity -@Table(name = "Cluster") -@SQLDelete(sql = "Update Cluster set isDeleted = 1 where id = ?") -@Where(clause = "isDeleted = 0") +@Table(name = "cluster") +@SQLDelete(sql = "UPDATE cluster SET deleted = TRUE WHERE id = ?") +@Where(clause = "NOT deleted") +@SequenceGenerator(name = "sequence", sequenceName = "cluster_id_seq", allocationSize = 1) public class Cluster extends BaseEntity implements Comparable { - @Column(name = "Name", nullable = false) + @Column(name = "cluster_name", nullable = false) private String name; - @Column(name = "AppId", nullable = false) + @Column(name = "app_id", nullable = false) private String appId; - @Column(name = "ParentClusterId", nullable = false) + @Column(name = "parent_cluster_id", nullable = false) private long parentClusterId; public String getAppId() { diff --git a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/Commit.java b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/Commit.java index 73776343a46..16f962627db 100644 --- a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/Commit.java +++ b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/Commit.java @@ -7,29 +7,29 @@ import javax.persistence.Column; import javax.persistence.Entity; -import javax.persistence.Lob; +import javax.persistence.SequenceGenerator; import javax.persistence.Table; @Entity -@Table(name = "Commit") -@SQLDelete(sql = "Update Commit set isDeleted = 1 where id = ?") -@Where(clause = "isDeleted = 0") +@Table(name = "commit") +@SQLDelete(sql = "UPDATE commit SET deleted = TRUE WHERE id = ?") +@Where(clause = "NOT deleted") +@SequenceGenerator(name = "sequence", sequenceName = "commit_id_seq", allocationSize = 1) public class Commit extends BaseEntity { - @Lob - @Column(name = "ChangeSets", nullable = false) + @Column(name = "change_sets", nullable = false) private String changeSets; - @Column(name = "AppId", nullable = false) + @Column(name = "app_id", nullable = false) private String appId; - @Column(name = "ClusterName", nullable = false) + @Column(name = "cluster_name", nullable = false) private String clusterName; - @Column(name = "NamespaceName", nullable = false) + @Column(name = "namespace_name", nullable = false) private String namespaceName; - @Column(name = "Comment") + @Column(name = "comment") private String comment; public String getChangeSets() { diff --git a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/GrayReleaseRule.java b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/GrayReleaseRule.java index bb1a106d1c9..c290a6a204d 100644 --- a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/GrayReleaseRule.java +++ b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/GrayReleaseRule.java @@ -7,33 +7,35 @@ import javax.persistence.Column; import javax.persistence.Entity; +import javax.persistence.SequenceGenerator; import javax.persistence.Table; @Entity -@Table(name = "GrayReleaseRule") -@SQLDelete(sql = "Update GrayReleaseRule set isDeleted = 1 where id = ?") -@Where(clause = "isDeleted = 0") +@Table(name = "gray_release_rule") +@SQLDelete(sql = "UPDATE gray_release_rule SET deleted = TRUE WHERE id = ?") +@Where(clause = "NOT deleted") +@SequenceGenerator(name = "sequence", sequenceName = "gray_release_rule_id_seq", allocationSize = 1) public class GrayReleaseRule extends BaseEntity{ - @Column(name = "appId", nullable = false) + @Column(name = "app_id", nullable = false) private String appId; - @Column(name = "ClusterName", nullable = false) + @Column(name = "cluster_name", nullable = false) private String clusterName; - @Column(name = "NamespaceName", nullable = false) + @Column(name = "namespace_name", nullable = false) private String namespaceName; - @Column(name = "BranchName", nullable = false) + @Column(name = "branch_name", nullable = false) private String branchName; - @Column(name = "Rules") + @Column(name = "rules") private String rules; - @Column(name = "releaseId", nullable = false) + @Column(name = "release_id", nullable = false) private Long releaseId; - @Column(name = "BranchStatus", nullable = false) + @Column(name = "branch_status", nullable = false) private int branchStatus; public String getAppId() { diff --git a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/Instance.java b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/Instance.java index 4d7894f056d..98f84cb31e5 100644 --- a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/Instance.java +++ b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/Instance.java @@ -9,35 +9,38 @@ import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.PrePersist; +import javax.persistence.SequenceGenerator; +import javax.persistence.GenerationType; import javax.persistence.Table; /** * @author Jason Song(song_s@ctrip.com) */ @Entity -@Table(name = "Instance") +@Table(name = "instance") +@SequenceGenerator(name = "sequence", sequenceName = "instance_id_seq", allocationSize = 1) public class Instance { @Id - @GeneratedValue - @Column(name = "Id") + @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sequence") + @Column(name = "id") private long id; - @Column(name = "AppId", nullable = false) + @Column(name = "app_id", nullable = false) private String appId; - @Column(name = "ClusterName", nullable = false) + @Column(name = "cluster_name", nullable = false) private String clusterName; - @Column(name = "DataCenter", nullable = false) + @Column(name = "data_center", nullable = false) private String dataCenter; - @Column(name = "Ip", nullable = false) + @Column(name = "ip", nullable = false) private String ip; - @Column(name = "DataChange_CreatedTime", nullable = false) + @Column(name = "created_time", nullable = false) private Date dataChangeCreatedTime; - @Column(name = "DataChange_LastTime") + @Column(name = "last_modified_time") private Date dataChangeLastModifiedTime; @PrePersist diff --git a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/InstanceConfig.java b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/InstanceConfig.java index 381414356b4..1864854dcc7 100644 --- a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/InstanceConfig.java +++ b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/InstanceConfig.java @@ -10,41 +10,44 @@ import javax.persistence.Id; import javax.persistence.PrePersist; import javax.persistence.PreUpdate; +import javax.persistence.SequenceGenerator; +import javax.persistence.GenerationType; import javax.persistence.Table; /** * @author Jason Song(song_s@ctrip.com) */ @Entity -@Table(name = "InstanceConfig") +@Table(name = "instance_config") +@SequenceGenerator(name = "sequence", sequenceName = "instance_config_id_seq", allocationSize = 1) public class InstanceConfig { @Id - @GeneratedValue - @Column(name = "Id") + @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sequence") + @Column(name = "id") private long id; - @Column(name = "InstanceId") + @Column(name = "instance_id") private long instanceId; - @Column(name = "ConfigAppId", nullable = false) + @Column(name = "config_app_id", nullable = false) private String configAppId; - @Column(name = "ConfigClusterName", nullable = false) + @Column(name = "config_cluster_name", nullable = false) private String configClusterName; - @Column(name = "ConfigNamespaceName", nullable = false) + @Column(name = "config_namespace_name", nullable = false) private String configNamespaceName; - @Column(name = "ReleaseKey", nullable = false) + @Column(name = "release_key", nullable = false) private String releaseKey; - @Column(name = "ReleaseDeliveryTime", nullable = false) + @Column(name = "release_delivery_time", nullable = false) private Date releaseDeliveryTime; - @Column(name = "DataChange_CreatedTime", nullable = false) + @Column(name = "created_time", nullable = false) private Date dataChangeCreatedTime; - @Column(name = "DataChange_LastTime") + @Column(name = "last_modified_time") private Date dataChangeLastModifiedTime; @PrePersist diff --git a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/Item.java b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/Item.java index cbf7d0f0c25..a389d8b70dd 100644 --- a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/Item.java +++ b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/Item.java @@ -7,29 +7,29 @@ import javax.persistence.Column; import javax.persistence.Entity; -import javax.persistence.Lob; +import javax.persistence.SequenceGenerator; import javax.persistence.Table; @Entity -@Table(name = "Item") -@SQLDelete(sql = "Update Item set isDeleted = 1 where id = ?") -@Where(clause = "isDeleted = 0") +@Table(name = "item") +@SQLDelete(sql = "UPDATE item SET deleted = TRUE WHERE id = ?") +@Where(clause = "NOT deleted") +@SequenceGenerator(name = "sequence", sequenceName = "item_id_seq", allocationSize = 1) public class Item extends BaseEntity { - @Column(name = "NamespaceId", nullable = false) + @Column(name = "namespace_id", nullable = false) private long namespaceId; @Column(name = "key", nullable = false) private String key; @Column(name = "value") - @Lob private String value; @Column(name = "comment") private String comment; - @Column(name = "LineNum") + @Column(name = "line_num") private Integer lineNum; public String getComment() { diff --git a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/Namespace.java b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/Namespace.java index b594217a758..03c19867409 100644 --- a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/Namespace.java +++ b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/Namespace.java @@ -7,21 +7,23 @@ import javax.persistence.Column; import javax.persistence.Entity; +import javax.persistence.SequenceGenerator; import javax.persistence.Table; @Entity -@Table(name = "Namespace") -@SQLDelete(sql = "Update Namespace set isDeleted = 1 where id = ?") -@Where(clause = "isDeleted = 0") +@Table(name = "namespace") +@SQLDelete(sql = "UPDATE namespace SET deleted = TRUE WHERE id = ?") +@Where(clause = "NOT deleted") +@SequenceGenerator(name = "sequence", sequenceName = "namespace_id_seq", allocationSize = 1) public class Namespace extends BaseEntity { - @Column(name = "appId", nullable = false) + @Column(name = "app_id", nullable = false) private String appId; - @Column(name = "ClusterName", nullable = false) + @Column(name = "cluster_name", nullable = false) private String clusterName; - @Column(name = "NamespaceName", nullable = false) + @Column(name = "namespace_name", nullable = false) private String namespaceName; public Namespace(){ diff --git a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/NamespaceLock.java b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/NamespaceLock.java index 59bb7c2b6bf..ce7a730ff6f 100644 --- a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/NamespaceLock.java +++ b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/NamespaceLock.java @@ -6,14 +6,16 @@ import javax.persistence.Column; import javax.persistence.Entity; +import javax.persistence.SequenceGenerator; import javax.persistence.Table; @Entity -@Table(name = "NamespaceLock") -@Where(clause = "isDeleted = 0") +@Table(name = "namespace_lock") +@Where(clause = "NOT deleted") +@SequenceGenerator(name = "sequence", sequenceName = "namespace_lock_id_seq", allocationSize = 1) public class NamespaceLock extends BaseEntity{ - @Column(name = "NamespaceId") + @Column(name = "namespace_id") private long namespaceId; public long getNamespaceId() { diff --git a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/Privilege.java b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/Privilege.java index eaffe5064e2..04786dc9ed1 100644 --- a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/Privilege.java +++ b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/Privilege.java @@ -7,21 +7,23 @@ import javax.persistence.Column; import javax.persistence.Entity; +import javax.persistence.SequenceGenerator; import javax.persistence.Table; @Entity -@Table(name = "Privilege") -@SQLDelete(sql = "Update Privilege set isDeleted = 1 where id = ?") -@Where(clause = "isDeleted = 0") +@Table(name = "privilege") +@SQLDelete(sql = "UPDATE privilege SET deleted = TRUE WHERE id = ?") +@Where(clause = "NOT deleted") +@SequenceGenerator(name = "sequence", sequenceName = "privilege_id_seq", allocationSize = 1) public class Privilege extends BaseEntity { - @Column(name = "Name", nullable = false) + @Column(name = "name", nullable = false) private String name; - @Column(name = "PrivilType", nullable = false) - private String privilType; + @Column(name = "privilege_type", nullable = false) + private String privilegeType; - @Column(name = "NamespaceId") + @Column(name = "namespace_id") private long namespaceId; public String getName() { @@ -33,7 +35,7 @@ public long getNamespaceId() { } public String getPrivilType() { - return privilType; + return privilegeType; } public void setName(String name) { @@ -44,12 +46,12 @@ public void setNamespaceId(long namespaceId) { this.namespaceId = namespaceId; } - public void setPrivilType(String privilType) { - this.privilType = privilType; + public void setPrivilType(String privilegeType) { + this.privilegeType = privilegeType; } public String toString() { - return toStringHelper().add("namespaceId", namespaceId).add("privilType", privilType) + return toStringHelper().add("namespaceId", namespaceId).add("privilegeType", privilegeType) .add("name", name).toString(); } } diff --git a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/Release.java b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/Release.java index 1a4853597d1..2d2ec93e206 100644 --- a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/Release.java +++ b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/Release.java @@ -7,40 +7,40 @@ import javax.persistence.Column; import javax.persistence.Entity; -import javax.persistence.Lob; +import javax.persistence.SequenceGenerator; import javax.persistence.Table; /** * @author Jason Song(song_s@ctrip.com) */ @Entity -@Table(name = "Release") -@SQLDelete(sql = "Update Release set isDeleted = 1 where id = ?") -@Where(clause = "isDeleted = 0") +@Table(name = "release") +@SQLDelete(sql = "UPDATE release SET deleted = TRUE WHERE id = ?") +@Where(clause = "NOT deleted") +@SequenceGenerator(name = "sequence", sequenceName = "release_id_seq", allocationSize = 1) public class Release extends BaseEntity { - @Column(name = "ReleaseKey", nullable = false) + @Column(name = "release_key", nullable = false) private String releaseKey; - @Column(name = "Name", nullable = false) + @Column(name = "release_name", nullable = false) private String name; - @Column(name = "AppId", nullable = false) + @Column(name = "app_id", nullable = false) private String appId; - @Column(name = "ClusterName", nullable = false) + @Column(name = "cluster_name", nullable = false) private String clusterName; - @Column(name = "NamespaceName", nullable = false) + @Column(name = "namespace_name", nullable = false) private String namespaceName; - @Column(name = "Configurations", nullable = false) - @Lob + @Column(name = "configurations", nullable = false) private String configurations; - @Column(name = "Comment", nullable = false) + @Column(name = "comment", nullable = false) private String comment; - @Column(name = "IsAbandoned", columnDefinition = "Bit default '0'") + @Column(name = "abandoned") private boolean isAbandoned; public String getReleaseKey() { diff --git a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/ReleaseHistory.java b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/ReleaseHistory.java index 0cc7b6cfaaf..60c50614d94 100644 --- a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/ReleaseHistory.java +++ b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/ReleaseHistory.java @@ -7,38 +7,40 @@ import javax.persistence.Column; import javax.persistence.Entity; +import javax.persistence.SequenceGenerator; import javax.persistence.Table; /** * @author Jason Song(song_s@ctrip.com) */ @Entity -@Table(name = "ReleaseHistory") -@SQLDelete(sql = "Update ReleaseHistory set isDeleted = 1 where id = ?") -@Where(clause = "isDeleted = 0") +@Table(name = "release_history") +@SQLDelete(sql = "UPDATE release_history SET deleted = TRUE WHERE id = ?") +@Where(clause = "NOT deleted") +@SequenceGenerator(name = "sequence", sequenceName = "release_history_id_seq", allocationSize = 1) public class ReleaseHistory extends BaseEntity { - @Column(name = "AppId", nullable = false) + @Column(name = "app_id", nullable = false) private String appId; - @Column(name = "ClusterName", nullable = false) + @Column(name = "cluster_name", nullable = false) private String clusterName; - @Column(name = "NamespaceName", nullable = false) + @Column(name = "namespace_name", nullable = false) private String namespaceName; - @Column(name = "BranchName", nullable = false) + @Column(name = "branch_name", nullable = false) private String branchName; - @Column(name = "ReleaseId") + @Column(name = "release_id") private long releaseId; - @Column(name = "PreviousReleaseId") + @Column(name = "previous_release_id") private long previousReleaseId; - @Column(name = "Operation") + @Column(name = "operation") private int operation; - @Column(name = "OperationContext", nullable = false) + @Column(name = "operation_context", nullable = false) private String operationContext; public String getAppId() { diff --git a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/ReleaseMessage.java b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/ReleaseMessage.java index 020bb8899ea..3d6489836b4 100644 --- a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/ReleaseMessage.java +++ b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/ReleaseMessage.java @@ -9,23 +9,26 @@ import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.PrePersist; +import javax.persistence.SequenceGenerator; +import javax.persistence.GenerationType; import javax.persistence.Table; /** * @author Jason Song(song_s@ctrip.com) */ @Entity -@Table(name = "ReleaseMessage") +@Table(name = "release_message") +@SequenceGenerator(name = "sequence", sequenceName = "release_message_id_seq", allocationSize = 1) public class ReleaseMessage { @Id - @GeneratedValue - @Column(name = "Id") + @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sequence") + @Column(name = "id") private long id; - @Column(name = "Message", nullable = false) + @Column(name = "message", nullable = false) private String message; - @Column(name = "DataChange_LastTime") + @Column(name = "last_modified_time") private Date dataChangeLastModifiedTime; @PrePersist diff --git a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/ServerConfig.java b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/ServerConfig.java index 50338a5e545..90493096537 100644 --- a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/ServerConfig.java +++ b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/ServerConfig.java @@ -7,26 +7,28 @@ import javax.persistence.Column; import javax.persistence.Entity; +import javax.persistence.SequenceGenerator; import javax.persistence.Table; /** * @author Jason Song(song_s@ctrip.com) */ @Entity -@Table(name = "ServerConfig") -@SQLDelete(sql = "Update ServerConfig set isDeleted = 1 where id = ?") -@Where(clause = "isDeleted = 0") +@Table(name = "server_config") +@SQLDelete(sql = "UPDATE server_config SET deleted = TRUE WHERE id = ?") +@Where(clause = "NOT deleted") +@SequenceGenerator(name = "sequence", sequenceName = "server_config_id_seq", allocationSize = 1) public class ServerConfig extends BaseEntity { - @Column(name = "Key", nullable = false) + @Column(name = "key", nullable = false) private String key; - @Column(name = "Cluster", nullable = false) + @Column(name = "cluster", nullable = false) private String cluster; - @Column(name = "Value", nullable = false) + @Column(name = "value", nullable = false) private String value; - @Column(name = "Comment", nullable = false) + @Column(name = "comment", nullable = false) private String comment; public String getKey() { diff --git a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/AppNamespaceRepository.java b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/AppNamespaceRepository.java index 99510958c5f..85589e00077 100644 --- a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/AppNamespaceRepository.java +++ b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/AppNamespaceRepository.java @@ -14,11 +14,11 @@ public interface AppNamespaceRepository extends PagingAndSortingRepository findByAppIdAndNameIn(String appId, Set namespaceNames); - AppNamespace findByNameAndIsPublicTrue(String namespaceName); + AppNamespace findByNameAndPubliccIsTrue(String namespaceName); - List findByNameInAndIsPublicTrue(Set namespaceNames); + List findByNameInAndPubliccIsTrue(Set namespaceNames); - List findByAppIdAndIsPublic(String appId, boolean isPublic); + List findByAppIdAndPublicc(String appId, boolean publicc); List findByAppId(String appId); diff --git a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/AppRepository.java b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/AppRepository.java index f665307d514..bf7114127ef 100644 --- a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/AppRepository.java +++ b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/AppRepository.java @@ -10,7 +10,7 @@ public interface AppRepository extends PagingAndSortingRepository { - @Query("SELECT a from App a WHERE a.name LIKE %:name%") + @Query("SELECT a FROM App a WHERE a.name LIKE %:name%") List findByName(@Param("name") String name); App findByAppId(String appId); diff --git a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/AuditRepository.java b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/AuditRepository.java index c1a1413bc6f..56391c0c6d6 100644 --- a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/AuditRepository.java +++ b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/AuditRepository.java @@ -10,10 +10,10 @@ public interface AuditRepository extends PagingAndSortingRepository { - @Query("SELECT a from Audit a WHERE a.dataChangeCreatedBy = :owner") + @Query("SELECT a FROM Audit a WHERE a.dataChangeCreatedBy = :owner") List findByOwner(@Param("owner") String owner); - @Query("SELECT a from Audit a WHERE a.dataChangeCreatedBy = :owner AND a.entityName =:entity AND a.opName = :op") + @Query("SELECT a FROM Audit a WHERE a.dataChangeCreatedBy = :owner AND a.entityName =:entity AND a.opName = :op") List findAudits(@Param("owner") String owner, @Param("entity") String entity, @Param("op") String op); } diff --git a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/CommitRepository.java b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/CommitRepository.java index 35835688b5d..72d3432b2bf 100644 --- a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/CommitRepository.java +++ b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/CommitRepository.java @@ -15,7 +15,7 @@ List findByAppIdAndClusterNameAndNamespaceNameOrderByIdDesc(String appId String namespaceName, Pageable pageable); @Modifying - @Query("update Commit set isdeleted=1,DataChange_LastModifiedBy = ?4 where appId=?1 and clusterName=?2 and namespaceName = ?3") + @Query("UPDATE Commit SET deleted = TRUE, dataChangeLastModifiedBy = ?4 WHERE appId = ?1 AND clusterName = ?2 AND namespaceName = ?3") int batchDelete(String appId, String clusterName, String namespaceName, String operator); } diff --git a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/InstanceConfigRepository.java b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/InstanceConfigRepository.java index e4c38c0c426..e96dc601ee4 100644 --- a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/InstanceConfigRepository.java +++ b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/InstanceConfigRepository.java @@ -28,19 +28,19 @@ List findByConfigAppIdAndConfigClusterNameAndConfigNamespaceName String appId, String clusterName, String namespaceName, Date validDate, Set releaseKey); @Modifying - @Query("delete from InstanceConfig where ConfigAppId=?1 and ConfigClusterName=?2 and ConfigNamespaceName = ?3") + @Query("DELETE FROM InstanceConfig WHERE configAppId = ?1 AND configClusterName = ?2 AND configNamespaceName = ?3") int batchDelete(String appId, String clusterName, String namespaceName); @Query( - value = "select b.Id from `InstanceConfig` a inner join `Instance` b on b.Id =" + - " a.`InstanceId` where a.`ConfigAppId` = :configAppId and a.`ConfigClusterName` = " + - ":clusterName and a.`ConfigNamespaceName` = :namespaceName and a.`DataChange_LastTime` " + - "> :validDate and b.`AppId` = :instanceAppId and ?#{#pageable.pageSize} > 0", - countQuery = "select count(1) from `InstanceConfig` a inner join `Instance` b on b.id =" + - " a.`InstanceId` where a.`ConfigAppId` = :configAppId and a.`ConfigClusterName` = " + - ":clusterName and a.`ConfigNamespaceName` = :namespaceName and a.`DataChange_LastTime` " + - "> :validDate and b.`AppId` = :instanceAppId", - nativeQuery = true) + value = "SELECT b.id FROM instance_config a INNER JOIN instance b ON b.id = " + + "a.instance_id WHERE a.config_app_id = :configAppId AND a.config_cluster_name = " + + ":clusterName AND a.config_namespace_name = :namespaceName AND a.last_modified_time " + + "> :validDate AND b.app_id = :instanceAppId AND ?#{#pageable.pageSize} > 0", + countQuery = "SELECT count(1) FROM instance_config a INNER JOIN instance b ON b.id = " + + " a.instance_id WHERE a.config_app_id = :configAppId AND a.config_cluster_name = " + + ":clusterName AND a.config_namespace_name = :namespaceName AND a.last_modified_time " + + "> :validDate AND b.app_id = :instanceAppId", + nativeQuery = true) Page findInstanceIdsByNamespaceAndInstanceAppId( @Param("instanceAppId") String instanceAppId, @Param("configAppId") String configAppId, @Param("clusterName") String clusterName, @Param("namespaceName") String namespaceName, diff --git a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/ItemRepository.java b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/ItemRepository.java index a8f03bd04ed..c49e9ec30e2 100644 --- a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/ItemRepository.java +++ b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/ItemRepository.java @@ -22,7 +22,7 @@ public interface ItemRepository extends PagingAndSortingRepository { Item findFirst1ByNamespaceIdOrderByLineNumDesc(Long namespaceId); @Modifying - @Query("update Item set isdeleted=1,DataChange_LastModifiedBy = ?2 where namespaceId = ?1") + @Query("UPDATE Item SET deleted = TRUE, dataChangeLastModifiedBy = ?2 WHERE namespaceId = ?1") int deleteByNamespaceId(long namespaceId, String operator); } diff --git a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/NamespaceRepository.java b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/NamespaceRepository.java index 6ddeece61d5..c0dc3ef8c37 100644 --- a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/NamespaceRepository.java +++ b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/NamespaceRepository.java @@ -17,7 +17,7 @@ public interface NamespaceRepository extends PagingAndSortingRepository findByAppIdAndNamespaceName(String appId, String namespaceName); diff --git a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/PrivilegeRepository.java b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/PrivilegeRepository.java index 5d2c9873334..c49f32ba982 100644 --- a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/PrivilegeRepository.java +++ b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/PrivilegeRepository.java @@ -10,7 +10,7 @@ public interface PrivilegeRepository extends PagingAndSortingRepository findByNamespaceId(long namespaceId); - List findByNamespaceIdAndPrivilType(long namespaceId, String privilType); + List findByNamespaceIdAndPrivilegeType(long namespaceId, String privilegeType); - Privilege findByNamespaceIdAndNameAndPrivilType(long namespaceId, String name, String privilType); + Privilege findByNamespaceIdAndNameAndPrivilegeType(long namespaceId, String name, String privilegeType); } diff --git a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/ReleaseHistoryRepository.java b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/ReleaseHistoryRepository.java index 0225e18e6da..bfd8e9e09fb 100644 --- a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/ReleaseHistoryRepository.java +++ b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/ReleaseHistoryRepository.java @@ -22,7 +22,7 @@ Page findByAppIdAndClusterNameAndNamespaceNameOrderByIdDesc(Stri Page findByPreviousReleaseIdAndOperationOrderByIdDesc(long previousReleaseId, int operation, Pageable pageable); @Modifying - @Query("update ReleaseHistory set isdeleted=1,DataChange_LastModifiedBy = ?4 where appId=?1 and clusterName=?2 and namespaceName = ?3") + @Query("UPDATE ReleaseHistory SET deleted = TRUE, dataChangeLastModifiedBy = ?4 WHERE appId = ?1 AND clusterName = ?2 AND namespaceName = ?3") int batchDelete(String appId, String clusterName, String namespaceName, String operator); } diff --git a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/ReleaseMessageRepository.java b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/ReleaseMessageRepository.java index 466d3491bfc..d75590847d4 100644 --- a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/ReleaseMessageRepository.java +++ b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/ReleaseMessageRepository.java @@ -21,6 +21,6 @@ public interface ReleaseMessageRepository extends PagingAndSortingRepository findFirst100ByMessageAndIdLessThanOrderByIdAsc(String message, Long id); - @Query("select message, max(id) as id from ReleaseMessage where message in :messages group by message") + @Query("SELECT message, max(id) AS id FROM ReleaseMessage WHERE message IN :messages GROUP BY message") List findLatestReleaseMessagesGroupByMessages(@Param("messages") Collection messages); } diff --git a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/ReleaseRepository.java b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/ReleaseRepository.java index ceb9827aaaf..73043f7db91 100644 --- a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/ReleaseRepository.java +++ b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/ReleaseRepository.java @@ -16,21 +16,21 @@ */ public interface ReleaseRepository extends PagingAndSortingRepository { - Release findFirstByAppIdAndClusterNameAndNamespaceNameAndIsAbandonedFalseOrderByIdDesc(@Param("appId") String appId, @Param("clusterName") String clusterName, + Release findFirstByAppIdAndClusterNameAndNamespaceNameAndAbandonedIsFalseOrderByIdDesc(@Param("appId") String appId, @Param("clusterName") String clusterName, @Param("namespaceName") String namespaceName); - Release findByIdAndIsAbandonedFalse(long id); + Release findByIdAndAbandonedIsFalse(long id); List findByAppIdAndClusterNameAndNamespaceNameOrderByIdDesc(String appId, String clusterName, String namespaceName, Pageable page); - List findByAppIdAndClusterNameAndNamespaceNameAndIsAbandonedFalseOrderByIdDesc(String appId, String clusterName, String namespaceName, Pageable page); + List findByAppIdAndClusterNameAndNamespaceNameAndAbandonedIsFalseOrderByIdDesc(String appId, String clusterName, String namespaceName, Pageable page); List findByReleaseKeyIn(Set releaseKey); List findByIdIn(Set releaseIds); @Modifying - @Query("update Release set isdeleted=1,DataChange_LastModifiedBy = ?4 where appId=?1 and clusterName=?2 and namespaceName = ?3") + @Query("UPDATE Release SET deleted = TRUE, dataChangeLastModifiedBy = ?4 WHERE appId =?1 AND clusterName = ?2 AND namespaceName = ?3") int batchDelete(String appId, String clusterName, String namespaceName, String operator); // For release history conversion program, need to delete after conversion it done diff --git a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/AppNamespaceService.java b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/AppNamespaceService.java index 92d3701f335..bb9a3514529 100644 --- a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/AppNamespaceService.java +++ b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/AppNamespaceService.java @@ -43,7 +43,7 @@ public boolean isAppNamespaceNameUnique(String appId, String namespaceName) { public AppNamespace findPublicNamespaceByName(String namespaceName) { Preconditions.checkArgument(namespaceName != null, "Namespace must not be null"); - return appNamespaceRepository.findByNameAndIsPublicTrue(namespaceName); + return appNamespaceRepository.findByNameAndPubliccIsTrue(namespaceName); } public List findByAppId(String appId) { @@ -55,11 +55,11 @@ public List findPublicNamespacesByNames(Set namespaceNames return Collections.emptyList(); } - return appNamespaceRepository.findByNameInAndIsPublicTrue(namespaceNames); + return appNamespaceRepository.findByNameInAndPubliccIsTrue(namespaceNames); } public List findPrivateAppNamespace(String appId) { - return appNamespaceRepository.findByAppIdAndIsPublic(appId, false); + return appNamespaceRepository.findByAppIdAndPublicc(appId, false); } public AppNamespace findOne(String appId, String namespaceName) { diff --git a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/ReleaseService.java b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/ReleaseService.java index ee8b2d4db21..b6280a7433b 100644 --- a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/ReleaseService.java +++ b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/ReleaseService.java @@ -69,7 +69,7 @@ public Release findOne(long releaseId) { public Release findActiveOne(long releaseId) { - return releaseRepository.findByIdAndIsAbandonedFalse(releaseId); + return releaseRepository.findByIdAndAbandonedIsFalse(releaseId); } public List findByReleaseIds(Set releaseIds) { @@ -91,7 +91,7 @@ public Release findLatestActiveRelease(Namespace namespace) { } public Release findLatestActiveRelease(String appId, String clusterName, String namespaceName) { - return releaseRepository.findFirstByAppIdAndClusterNameAndNamespaceNameAndIsAbandonedFalseOrderByIdDesc(appId, + return releaseRepository.findFirstByAppIdAndClusterNameAndNamespaceNameAndAbandonedIsFalseOrderByIdDesc(appId, clusterName, namespaceName); } @@ -110,7 +110,7 @@ public List findAllReleases(String appId, String clusterName, String na public List findActiveReleases(String appId, String clusterName, String namespaceName, Pageable page) { List releases = - releaseRepository.findByAppIdAndClusterNameAndNamespaceNameAndIsAbandonedFalseOrderByIdDesc(appId, clusterName, + releaseRepository.findByAppIdAndClusterNameAndNamespaceNameAndAbandonedIsFalseOrderByIdDesc(appId, clusterName, namespaceName, page); if (releases == null) { diff --git a/apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/repository/AppNamespaceRepositoryTest.java b/apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/repository/AppNamespaceRepositoryTest.java index e7c1356d458..4815a59d7d2 100644 --- a/apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/repository/AppNamespaceRepositoryTest.java +++ b/apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/repository/AppNamespaceRepositoryTest.java @@ -16,14 +16,14 @@ public class AppNamespaceRepositoryTest extends AbstractIntegrationTest{ @Test public void testFindByNameAndIsPublicTrue() throws Exception { - AppNamespace appNamespace = repository.findByNameAndIsPublicTrue("fx.apollo.config"); + AppNamespace appNamespace = repository.findByNameAndPubliccIsTrue("fx.apollo.config"); assertEquals("100003171", appNamespace.getAppId()); } @Test public void testFindByNameAndNoPublicNamespace() throws Exception { - AppNamespace appNamespace = repository.findByNameAndIsPublicTrue("application"); + AppNamespace appNamespace = repository.findByNameAndPubliccIsTrue("application"); assertNull(appNamespace); } diff --git a/apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/service/ReleaseServiceTest.java b/apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/service/ReleaseServiceTest.java index cb56341049d..4739c09a292 100644 --- a/apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/service/ReleaseServiceTest.java +++ b/apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/service/ReleaseServiceTest.java @@ -80,7 +80,7 @@ public void testNamespaceNotExist() { public void testHasNoRelease() { when(releaseRepository.findOne(releaseId)).thenReturn(firstRelease); - when(releaseRepository.findByAppIdAndClusterNameAndNamespaceNameAndIsAbandonedFalseOrderByIdDesc(appId, + when(releaseRepository.findByAppIdAndClusterNameAndNamespaceNameAndAbandonedIsFalseOrderByIdDesc(appId, clusterName, namespaceName, pageRequest)) @@ -93,7 +93,7 @@ public void testHasNoRelease() { public void testRollback() { when(releaseRepository.findOne(releaseId)).thenReturn(firstRelease); - when(releaseRepository.findByAppIdAndClusterNameAndNamespaceNameAndIsAbandonedFalseOrderByIdDesc(appId, + when(releaseRepository.findByAppIdAndClusterNameAndNamespaceNameAndAbandonedIsFalseOrderByIdDesc(appId, clusterName, namespaceName, pageRequest)) @@ -122,7 +122,7 @@ public void testFindRelease() throws Exception { someNamespaceName, someValidConfiguration); - when(releaseRepository.findFirstByAppIdAndClusterNameAndNamespaceNameAndIsAbandonedFalseOrderByIdDesc(someAppId, + when(releaseRepository.findFirstByAppIdAndClusterNameAndNamespaceNameAndAbandonedIsFalseOrderByIdDesc(someAppId, someClusterName, someNamespaceName)) .thenReturn(someRelease); @@ -130,7 +130,7 @@ public void testFindRelease() throws Exception { Release result = releaseService.findLatestActiveRelease(someAppId, someClusterName, someNamespaceName); verify(releaseRepository, times(1)) - .findFirstByAppIdAndClusterNameAndNamespaceNameAndIsAbandonedFalseOrderByIdDesc(someAppId, someClusterName, + .findFirstByAppIdAndClusterNameAndNamespaceNameAndAbandonedIsFalseOrderByIdDesc(someAppId, someClusterName, someNamespaceName); assertEquals(someAppId, result.getAppId()); assertEquals(someClusterName, result.getClusterName()); @@ -145,7 +145,7 @@ public void testLoadConfigWithConfigNotFound() throws Exception { String someClusterName = "someClusterName"; String someNamespaceName = "someNamespaceName"; - when(releaseRepository.findFirstByAppIdAndClusterNameAndNamespaceNameAndIsAbandonedFalseOrderByIdDesc(someAppId, + when(releaseRepository.findFirstByAppIdAndClusterNameAndNamespaceNameAndAbandonedIsFalseOrderByIdDesc(someAppId, someClusterName, someNamespaceName)) .thenReturn(null); @@ -153,7 +153,7 @@ public void testLoadConfigWithConfigNotFound() throws Exception { Release result = releaseService.findLatestActiveRelease(someAppId, someClusterName, someNamespaceName); assertNull(result); - verify(releaseRepository, times(1)).findFirstByAppIdAndClusterNameAndNamespaceNameAndIsAbandonedFalseOrderByIdDesc( + verify(releaseRepository, times(1)).findFirstByAppIdAndClusterNameAndNamespaceNameAndAbandonedIsFalseOrderByIdDesc( someAppId, someClusterName, someNamespaceName); } diff --git a/apollo-common/pom.xml b/apollo-common/pom.xml index 1da71ff248c..dccf7d49b7a 100644 --- a/apollo-common/pom.xml +++ b/apollo-common/pom.xml @@ -46,8 +46,8 @@ spring-boot-starter-data-jpa - mysql - mysql-connector-java + org.postgresql + postgresql org.springframework.data diff --git a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/entity/App.java b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/entity/App.java index ac108ba8ef0..e1785872938 100644 --- a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/entity/App.java +++ b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/entity/App.java @@ -5,30 +5,32 @@ import javax.persistence.Column; import javax.persistence.Entity; +import javax.persistence.SequenceGenerator; import javax.persistence.Table; @Entity -@Table(name = "App") -@SQLDelete(sql = "Update App set isDeleted = 1 where id = ?") -@Where(clause = "isDeleted = 0") +@Table(name = "app") +@SQLDelete(sql = "UPDATE app SET deleted = TRUE WHERE id = ?") +@Where(clause = "NOT deleted") +@SequenceGenerator(name = "sequence", sequenceName = "app_id_seq", allocationSize = 1) public class App extends BaseEntity { - @Column(name = "Name", nullable = false) + @Column(name = "app_name", nullable = false) private String name; - @Column(name = "AppId", nullable = false) + @Column(name = "app_id", nullable = false) private String appId; - @Column(name = "OrgId", nullable = false) + @Column(name = "org_id", nullable = false) private String orgId; - @Column(name = "OrgName", nullable = false) + @Column(name = "org_name", nullable = false) private String orgName; - @Column(name = "OwnerName", nullable = false) + @Column(name = "owner_name", nullable = false) private String ownerName; - @Column(name = "OwnerEmail", nullable = false) + @Column(name = "owner_email", nullable = false) private String ownerEmail; public String getAppId() { diff --git a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/entity/AppNamespace.java b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/entity/AppNamespace.java index bb77d05c7f4..41da545caf6 100644 --- a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/entity/AppNamespace.java +++ b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/entity/AppNamespace.java @@ -8,27 +8,29 @@ import javax.persistence.Column; import javax.persistence.Entity; +import javax.persistence.SequenceGenerator; import javax.persistence.Table; @Entity -@Table(name = "AppNamespace") -@SQLDelete(sql = "Update AppNamespace set isDeleted = 1 where id = ?") -@Where(clause = "isDeleted = 0") +@Table(name = "app_namespace") +@SQLDelete(sql = "UPDATE app_namespace SET deleted = TRUE WHERE id = ?") +@Where(clause = "NOT deleted") +@SequenceGenerator(name = "sequence", sequenceName = "app_namespace_id_seq", allocationSize = 1) public class AppNamespace extends BaseEntity { - @Column(name = "Name", nullable = false) + @Column(name = "namespace_name", nullable = false) private String name; - @Column(name = "AppId", nullable = false) + @Column(name = "app_id", nullable = false) private String appId; - @Column(name = "Format", nullable = false) + @Column(name = "format", nullable = false) private String format; - @Column(name = "IsPublic", columnDefinition = "Bit default '0'") - private boolean isPublic = false; + @Column(name = "shared") + private boolean publicc = false; - @Column(name = "Comment") + @Column(name = "comment") private String comment; public String getAppId() { @@ -56,11 +58,11 @@ public void setName(String name) { } public boolean isPublic() { - return isPublic; + return publicc; } - public void setPublic(boolean aPublic) { - isPublic = aPublic; + public void setPublic(boolean publicc) { + this.publicc = publicc; } public ConfigFileFormat formatAsEnum() { @@ -77,6 +79,6 @@ public void setFormat(String format) { public String toString() { return toStringHelper().add("name", name).add("appId", appId).add("comment", comment) - .add("format", format).add("isPublic", isPublic).toString(); + .add("format", format).add("isPublic", publicc).toString(); } } diff --git a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/entity/BaseEntity.java b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/entity/BaseEntity.java index bbbc621e203..3e0e7e8bcf8 100644 --- a/apollo-common/src/main/java/com/ctrip/framework/apollo/common/entity/BaseEntity.java +++ b/apollo-common/src/main/java/com/ctrip/framework/apollo/common/entity/BaseEntity.java @@ -14,29 +14,30 @@ import javax.persistence.PrePersist; import javax.persistence.PreRemove; import javax.persistence.PreUpdate; +import javax.persistence.GenerationType; @MappedSuperclass @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) public abstract class BaseEntity { @Id - @GeneratedValue - @Column(name = "Id") + @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sequence") + @Column(name = "id") private long id; - @Column(name = "IsDeleted", columnDefinition = "Bit default '0'") + @Column(name = "deleted", nullable = false) protected boolean isDeleted = false; - @Column(name = "DataChange_CreatedBy", nullable = false) + @Column(name = "created_by", nullable = false) private String dataChangeCreatedBy; - @Column(name = "DataChange_CreatedTime", nullable = false) + @Column(name = "created_time", nullable = false) private Date dataChangeCreatedTime; - @Column(name = "DataChange_LastModifiedBy") + @Column(name = "last_modified_by") private String dataChangeLastModifiedBy; - @Column(name = "DataChange_LastTime") + @Column(name = "last_modified_time") private Date dataChangeLastModifiedTime; public String getDataChangeCreatedBy() { diff --git a/apollo-common/src/main/resources/application.properties b/apollo-common/src/main/resources/application.properties index c6acc4facdd..fea8fd0411d 100644 --- a/apollo-common/src/main/resources/application.properties +++ b/apollo-common/src/main/resources/application.properties @@ -5,13 +5,17 @@ spring.datasource.testWhileIdle=true spring.datasource.testOnBorrow=true spring.datasource.validationQuery=SELECT 1 spring.datasource.validationInterval=5000 -spring.datasource.initSQL=set names utf8mb4 +# spring.datasource.initSQL=set names utf8mb4 # Naming strategy spring.jpa.hibernate.naming_strategy=org.hibernate.cfg.EJB3NamingStrategy spring.jpa.hibernate.globally_quoted_identifiers=true spring.jpa.properties.hibernate.globally_quoted_identifiers=true +# dialect +spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQL9Dialect +spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults=false + # Tomcat configuration server.tomcat.accept-count=5000 # Increase tomcat header size for longer GET query parameter, should be n * 1024 diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/entity/Consumer.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/entity/Consumer.java index 79e5e5488d9..b3a770e7afd 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/entity/Consumer.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/entity/Consumer.java @@ -7,30 +7,32 @@ import javax.persistence.Column; import javax.persistence.Entity; +import javax.persistence.SequenceGenerator; import javax.persistence.Table; @Entity -@Table(name = "Consumer") -@SQLDelete(sql = "Update Consumer set isDeleted = 1 where id = ?") -@Where(clause = "isDeleted = 0") +@Table(name = "consumer") +@SQLDelete(sql = "UPDATE consumer SET deleted = TRUE WHERE id = ?") +@Where(clause = "NOT deleted") +@SequenceGenerator(name = "sequence", sequenceName = "consumer_id_seq", allocationSize = 1) public class Consumer extends BaseEntity { - @Column(name = "Name", nullable = false) + @Column(name = "consumer_name", nullable = false) private String name; - @Column(name = "AppId", nullable = false) + @Column(name = "app_id", nullable = false) private String appId; - @Column(name = "OrgId", nullable = false) + @Column(name = "org_id", nullable = false) private String orgId; - @Column(name = "OrgName", nullable = false) + @Column(name = "org_name", nullable = false) private String orgName; - @Column(name = "OwnerName", nullable = false) + @Column(name = "owner_name", nullable = false) private String ownerName; - @Column(name = "OwnerEmail", nullable = false) + @Column(name = "owner_email", nullable = false) private String ownerEmail; public String getAppId() { diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/entity/ConsumerAudit.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/entity/ConsumerAudit.java index 6944ae7aa1b..7700740e8ed 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/entity/ConsumerAudit.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/entity/ConsumerAudit.java @@ -9,32 +9,35 @@ import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.PrePersist; +import javax.persistence.SequenceGenerator; +import javax.persistence.GenerationType; import javax.persistence.Table; /** * @author Jason Song(song_s@ctrip.com) */ @Entity -@Table(name = "ConsumerAudit") +@Table(name = "consumer_audit") +@SequenceGenerator(name = "sequence", sequenceName = "consumer_audit_id_seq", allocationSize = 1) public class ConsumerAudit { @Id - @GeneratedValue - @Column(name = "Id") + @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sequence") + @Column(name = "id") private long id; - @Column(name = "ConsumerId", nullable = false) + @Column(name = "consumer_id", nullable = false) private long consumerId; - @Column(name = "Uri", nullable = false) + @Column(name = "uri", nullable = false) private String uri; - @Column(name = "Method", nullable = false) + @Column(name = "method", nullable = false) private String method; - @Column(name = "DataChange_CreatedTime") + @Column(name = "created_time") private Date dataChangeCreatedTime; - @Column(name = "DataChange_LastTime") + @Column(name = "last_modified_time") private Date dataChangeLastModifiedTime; @PrePersist diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/entity/ConsumerRole.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/entity/ConsumerRole.java index fae23418786..abc81c95edb 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/entity/ConsumerRole.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/entity/ConsumerRole.java @@ -7,20 +7,22 @@ import javax.persistence.Column; import javax.persistence.Entity; +import javax.persistence.SequenceGenerator; import javax.persistence.Table; /** * @author Jason Song(song_s@ctrip.com) */ @Entity -@Table(name = "ConsumerRole") -@SQLDelete(sql = "Update ConsumerRole set isDeleted = 1 where id = ?") -@Where(clause = "isDeleted = 0") +@Table(name = "consumer_role") +@SQLDelete(sql = "UPDATE consumer_role SET deleted = TRUE WHERE id = ?") +@Where(clause = "NOT deleted") +@SequenceGenerator(name = "sequence", sequenceName = "consumer_role_id_seq", allocationSize = 1) public class ConsumerRole extends BaseEntity { - @Column(name = "ConsumerId", nullable = false) + @Column(name = "consumer_id", nullable = false) private long consumerId; - @Column(name = "RoleId", nullable = false) + @Column(name = "role_id", nullable = false) private long roleId; public long getConsumerId() { diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/entity/ConsumerToken.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/entity/ConsumerToken.java index c3ac59e27d3..706a1699ec4 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/entity/ConsumerToken.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/entity/ConsumerToken.java @@ -9,17 +9,19 @@ import javax.persistence.Column; import javax.persistence.Entity; +import javax.persistence.SequenceGenerator; import javax.persistence.Table; /** * @author Jason Song(song_s@ctrip.com) */ @Entity -@Table(name = "ConsumerToken") -@SQLDelete(sql = "Update ConsumerToken set isDeleted = 1 where id = ?") -@Where(clause = "isDeleted = 0") +@Table(name = "consumer_token") +@SQLDelete(sql = "UPDATE ConsumerToken SET deleted = TRUE WHERE id = ?") +@Where(clause = "NOT deleted") +@SequenceGenerator(name = "sequence", sequenceName = "consumer_token_id_seq", allocationSize = 1) public class ConsumerToken extends BaseEntity { - @Column(name = "ConsumerId", nullable = false) + @Column(name = "consumer_id", nullable = false) private long consumerId; @Column(name = "token", nullable = false) diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/entity/po/Favorite.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/entity/po/Favorite.java index 72facb5cf7d..f45c8c8eaac 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/entity/po/Favorite.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/entity/po/Favorite.java @@ -7,21 +7,23 @@ import javax.persistence.Column; import javax.persistence.Entity; +import javax.persistence.SequenceGenerator; import javax.persistence.Table; @Entity -@Table(name = "Favorite") -@SQLDelete(sql = "Update Favorite set isDeleted = 1 where id = ?") -@Where(clause = "isDeleted = 0") +@Table(name = "favorite") +@SQLDelete(sql = "UPDATE favorite SET deleted = TRUE WHERE id = ?") +@Where(clause = "NOT deleted") +@SequenceGenerator(name = "sequence", sequenceName = "favorite_id_seq", allocationSize = 1) public class Favorite extends BaseEntity { - @Column(name = "AppId", nullable = false) + @Column(name = "app_id", nullable = false) private String appId; - @Column(name = "UserId", nullable = false) + @Column(name = "user_id", nullable = false) private String userId; - @Column(name = "Position") + @Column(name = "favorite_position") private long position; public String getAppId() { diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/entity/po/Permission.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/entity/po/Permission.java index 5addf790405..5a5a8863579 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/entity/po/Permission.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/entity/po/Permission.java @@ -7,20 +7,22 @@ import javax.persistence.Column; import javax.persistence.Entity; +import javax.persistence.SequenceGenerator; import javax.persistence.Table; /** * @author Jason Song(song_s@ctrip.com) */ @Entity -@Table(name = "Permission") -@SQLDelete(sql = "Update Permission set isDeleted = 1 where id = ?") -@Where(clause = "isDeleted = 0") +@Table(name = "permission") +@SQLDelete(sql = "UPDATE permission SET deleted = TRUE WHERE id = ?") +@Where(clause = "NOT deleted") +@SequenceGenerator(name = "sequence", sequenceName = "permission_id_seq", allocationSize = 1) public class Permission extends BaseEntity { - @Column(name = "PermissionType", nullable = false) + @Column(name = "permission_type", nullable = false) private String permissionType; - @Column(name = "TargetId", nullable = false) + @Column(name = "target_id", nullable = false) private String targetId; public String getPermissionType() { diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/entity/po/Role.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/entity/po/Role.java index 545e8962d3c..01d181d7072 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/entity/po/Role.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/entity/po/Role.java @@ -7,17 +7,19 @@ import javax.persistence.Column; import javax.persistence.Entity; +import javax.persistence.SequenceGenerator; import javax.persistence.Table; /** * @author Jason Song(song_s@ctrip.com) */ @Entity -@Table(name = "Role") -@SQLDelete(sql = "Update Role set isDeleted = 1 where id = ?") -@Where(clause = "isDeleted = 0") +@Table(name = "role") +@SQLDelete(sql = "UPDATE role SET deleted = TRUE WHERE id = ?") +@Where(clause = "NOT deleted") +@SequenceGenerator(name = "sequence", sequenceName = "role_id_seq", allocationSize = 1) public class Role extends BaseEntity { - @Column(name = "RoleName", nullable = false) + @Column(name = "role_name", nullable = false) private String roleName; public String getRoleName() { diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/entity/po/RolePermission.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/entity/po/RolePermission.java index 099522ba51e..ab9d1787d24 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/entity/po/RolePermission.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/entity/po/RolePermission.java @@ -7,20 +7,22 @@ import javax.persistence.Column; import javax.persistence.Entity; +import javax.persistence.SequenceGenerator; import javax.persistence.Table; /** * @author Jason Song(song_s@ctrip.com) */ @Entity -@Table(name = "RolePermission") -@SQLDelete(sql = "Update RolePermission set isDeleted = 1 where id = ?") -@Where(clause = "isDeleted = 0") +@Table(name = "role_permission") +@SQLDelete(sql = "UPDATE role_permission SET deleted = TRUE WHERE id = ?") +@Where(clause = "NOT deleted") +@SequenceGenerator(name = "sequence", sequenceName = "role_permission_id_seq", allocationSize = 1) public class RolePermission extends BaseEntity { - @Column(name = "RoleId", nullable = false) + @Column(name = "role_id", nullable = false) private long roleId; - @Column(name = "PermissionId", nullable = false) + @Column(name = "permission_id", nullable = false) private long permissionId; public long getRoleId() { diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/entity/po/ServerConfig.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/entity/po/ServerConfig.java index a8fbff4fa9e..af27baefd3d 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/entity/po/ServerConfig.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/entity/po/ServerConfig.java @@ -7,23 +7,25 @@ import javax.persistence.Column; import javax.persistence.Entity; +import javax.persistence.SequenceGenerator; import javax.persistence.Table; /** * @author Jason Song(song_s@ctrip.com) */ @Entity -@Table(name = "ServerConfig") -@SQLDelete(sql = "Update ServerConfig set isDeleted = 1 where id = ?") -@Where(clause = "isDeleted = 0") +@Table(name = "server_config") +@SQLDelete(sql = "UPDATE server_config SET deleted = TRUE WHERE id = ?") +@Where(clause = "NOT deleted") +@SequenceGenerator(name = "sequence", sequenceName = "server_config_id_seq", allocationSize = 1) public class ServerConfig extends BaseEntity { - @Column(name = "Key", nullable = false) + @Column(name = "key", nullable = false) private String key; - @Column(name = "Value", nullable = false) + @Column(name = "value", nullable = false) private String value; - @Column(name = "Comment", nullable = false) + @Column(name = "comment", nullable = false) private String comment; public String getKey() { diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/entity/po/UserPO.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/entity/po/UserPO.java index ed4b8549931..d49b09fc2fe 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/entity/po/UserPO.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/entity/po/UserPO.java @@ -6,27 +6,30 @@ import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; +import javax.persistence.SequenceGenerator; +import javax.persistence.GenerationType; import javax.persistence.Table; /** * @author lepdou 2017-04-08 */ @Entity -@Table(name = "Users") +@Table(name = "users") +@SequenceGenerator(name = "sequence", sequenceName = "users_id_seq", allocationSize = 1) public class UserPO { @Id - @GeneratedValue - @Column(name = "Id") + @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sequence") + @Column(name = "id") private long id; - @Column(name = "Username", nullable = false) + @Column(name = "username", nullable = false) private String username; - @Column(name = "Password", nullable = false) + @Column(name = "password", nullable = false) private String password; - @Column(name = "Email", nullable = false) + @Column(name = "email", nullable = false) private String email; - @Column(name = "Enabled", nullable = false) - private int enabled; + @Column(name = "enabled", nullable = false) + private boolean enabled = true; public long getId() { return id; @@ -60,11 +63,11 @@ public void setPassword(String password) { this.password = password; } - public int getEnabled() { + public boolean isEnabled() { return enabled; } - public void setEnabled(int enabled) { + public void setEnabled(boolean enabled) { this.enabled = enabled; } diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/entity/po/UserRole.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/entity/po/UserRole.java index e6b0a866431..6da608d5fde 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/entity/po/UserRole.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/entity/po/UserRole.java @@ -7,20 +7,22 @@ import javax.persistence.Column; import javax.persistence.Entity; +import javax.persistence.SequenceGenerator; import javax.persistence.Table; /** * @author Jason Song(song_s@ctrip.com) */ @Entity -@Table(name = "UserRole") -@SQLDelete(sql = "Update UserRole set isDeleted = 1 where id = ?") -@Where(clause = "isDeleted = 0") +@Table(name = "user_role") +@SQLDelete(sql = "UPDATE user_role SET deleted = TRUE WHERE id = ?") +@Where(clause = "NOT deleted") +@SequenceGenerator(name = "sequence", sequenceName = "user_role_id_seq", allocationSize = 1) public class UserRole extends BaseEntity { - @Column(name = "UserId", nullable = false) + @Column(name = "user_id", nullable = false) private String userId; - @Column(name = "RoleId", nullable = false) + @Column(name = "role_id", nullable = false) private long roleId; public String getUserId() { diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/repository/AppNamespaceRepository.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/repository/AppNamespaceRepository.java index 59b1780060c..1b08a814461 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/repository/AppNamespaceRepository.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/repository/AppNamespaceRepository.java @@ -12,8 +12,8 @@ public interface AppNamespaceRepository extends PagingAndSortingRepository findByIsPublicTrue(); + List findByPubliccIsTrue(); } diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/repository/UserRepository.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/repository/UserRepository.java index 63fe2dc26d5..034a6f7679a 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/repository/UserRepository.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/repository/UserRepository.java @@ -11,9 +11,9 @@ */ public interface UserRepository extends PagingAndSortingRepository { - List findFirst20ByEnabled(int enabled); + List findFirst20ByEnabled(boolean enabled); - List findByUsernameLikeAndEnabled(String username, int enabled); + List findByUsernameLikeAndEnabled(String username, boolean enabled); UserPO findByUsername(String username); } diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/AppNamespaceService.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/AppNamespaceService.java index 680018aae3d..b38b74fcd9f 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/AppNamespaceService.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/AppNamespaceService.java @@ -33,11 +33,11 @@ public class AppNamespaceService { * 公共的app ns,能被其它项目关联到的app ns */ public List findPublicAppNamespaces() { - return appNamespaceRepository.findByIsPublicTrue(); + return appNamespaceRepository.findByPubliccIsTrue(); } public AppNamespace findPublicAppNamespace(String namespaceName) { - return appNamespaceRepository.findByNameAndIsPublic(namespaceName, true); + return appNamespaceRepository.findByNameAndPublicc(namespaceName, true); } public AppNamespace findByAppIdAndName(String appId, String namespaceName) { diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/configuration/AuthConfiguration.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/configuration/AuthConfiguration.java index f0f349b5968..07767a8adfd 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/configuration/AuthConfiguration.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/configuration/AuthConfiguration.java @@ -212,17 +212,17 @@ public LogoutHandler logoutHandler() { @Bean public JdbcUserDetailsManager jdbcUserDetailsManager(AuthenticationManagerBuilder auth, DataSource datasource) throws Exception { JdbcUserDetailsManager jdbcUserDetailsManager = auth.jdbcAuthentication().passwordEncoder(new BCryptPasswordEncoder()).dataSource(datasource) - .usersByUsernameQuery("select Username,Password,Enabled from `Users` where Username = ?") - .authoritiesByUsernameQuery("select Username,Authority from `Authorities` where Username = ?") + .usersByUsernameQuery("SELECT username, password, enabled FROM users WHERE username = ?") + .authoritiesByUsernameQuery("SELECT username, authority FROM authorities WHERE username = ?") .getUserDetailsService(); - jdbcUserDetailsManager.setUserExistsSql("select Username from `Users` where Username = ?"); - jdbcUserDetailsManager.setCreateUserSql("insert into `Users` (Username, Password, Enabled) values (?,?,?)"); - jdbcUserDetailsManager.setUpdateUserSql("update `Users` set Password = ?, Enabled = ? where Username = ?"); - jdbcUserDetailsManager.setDeleteUserSql("delete from `Users` where Username = ?"); - jdbcUserDetailsManager.setCreateAuthoritySql("insert into `Authorities` (Username, Authority) values (?,?)"); - jdbcUserDetailsManager.setDeleteUserAuthoritiesSql("delete from `Authorities` where Username = ?"); - jdbcUserDetailsManager.setChangePasswordSql("update `Users` set Password = ? where Username = ?"); + jdbcUserDetailsManager.setUserExistsSql("SELECT username FROM users WHERE username = ?"); + jdbcUserDetailsManager.setCreateUserSql("INSERT INTO users (username, password, enabled) VALUES (?, ?, ?)"); + jdbcUserDetailsManager.setUpdateUserSql("UPDATE users SET password = ?, enabled = ? WHERE username = ?"); + jdbcUserDetailsManager.setDeleteUserSql("DELETE FROM users WHERE username = ?"); + jdbcUserDetailsManager.setCreateAuthoritySql("INSERT INTO authorities (username, authority) VALUES (?, ?)"); + jdbcUserDetailsManager.setDeleteUserAuthoritiesSql("DELETE FROM authorities WHERE username = ?"); + jdbcUserDetailsManager.setChangePasswordSql("UPDATE users SET password = ? WHERE username = ?"); return jdbcUserDetailsManager; } diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/springsecurity/SpringSecurityUserService.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/springsecurity/SpringSecurityUserService.java index c71920dd2d4..bd10620ed73 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/springsecurity/SpringSecurityUserService.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/springsecurity/SpringSecurityUserService.java @@ -65,9 +65,9 @@ public void createOrUpdate(UserPO user) { public List searchUsers(String keyword, int offset, int limit) { List users; if (StringUtils.isEmpty(keyword)) { - users = userRepository.findFirst20ByEnabled(1); + users = userRepository.findFirst20ByEnabled(true); } else { - users = userRepository.findByUsernameLikeAndEnabled("%" + keyword + "%", 1); + users = userRepository.findByUsernameLikeAndEnabled("%" + keyword + "%", true); } List result = Lists.newArrayList(); diff --git a/pom.xml b/pom.xml index 5532b2af21e..d0b120eebeb 100644 --- a/pom.xml +++ b/pom.xml @@ -258,9 +258,9 @@ 2.8.0 - mysql - mysql-connector-java - 5.1.39 + org.postgresql + postgresql + 42.2.4 com.google.inject diff --git a/scripts/sql/pg-configdb.sql b/scripts/sql/pg-configdb.sql new file mode 100644 index 00000000000..6d72f216c01 --- /dev/null +++ b/scripts/sql/pg-configdb.sql @@ -0,0 +1,327 @@ +CREATE SEQUENCE app_id_seq + INCREMENT 1 + START 1; +CREATE TABLE app ( + id BIGINT NOT NULL DEFAULT nextval('app_id_seq'), + app_id TEXT NOT NULL DEFAULT 'default', + app_name TEXT NOT NULL DEFAULT 'default', + org_id TEXT NOT NULL DEFAULT 'default', + org_name TEXT NOT NULL DEFAULT 'default', + owner_name TEXT NOT NULL DEFAULT 'default', + owner_email TEXT NOT NULL DEFAULT 'default', + deleted BOOLEAN NOT NULL DEFAULT FALSE, + created_by TEXT NOT NULL DEFAULT 'default', + created_time TIMESTAMP NOT NULL DEFAULT now(), + last_modified_by TEXT DEFAULT '', + last_modified_time TIMESTAMP DEFAULT now() +); +CREATE INDEX app_app_id_index + ON app (app_id); +CREATE INDEX app_app_name_index + ON app (app_name); +CREATE INDEX app_last_modified_time_index + ON app (last_modified_time); + +CREATE SEQUENCE app_namespace_id_seq + INCREMENT 1 + START 1; +CREATE TABLE app_namespace ( + id BIGINT NOT NULL DEFAULT nextval('app_namespace_id_seq') PRIMARY KEY, + namespace_name TEXT NOT NULL DEFAULT '', + app_id TEXT NOT NULL DEFAULT '', + format TEXT NOT NULL DEFAULT 'properties', + shared BOOLEAN NOT NULL DEFAULT FALSE, + comment TEXT NOT NULL DEFAULT '', + deleted BOOLEAN NOT NULL DEFAULT FALSE, + created_by TEXT NOT NULL DEFAULT '', + created_time TIMESTAMP NOT NULL DEFAULT now(), + last_modified_by TEXT DEFAULT '', + last_modified_time TIMESTAMP DEFAULT now() +); +CREATE INDEX app_namespace_app_id_index + ON app_namespace (app_id); +CREATE INDEX app_namespace_namespace_name_app_id_index + ON app_namespace (namespace_name, app_id); +CREATE INDEX app_namespace_last_modified_time_index + ON app_namespace (last_modified_time); + +CREATE SEQUENCE audit_id_seq + INCREMENT 1 + START 1; +CREATE TABLE audit ( + id BIGINT NOT NULL DEFAULT nextval('audit_id_seq') PRIMARY KEY, + entity_name TEXT NOT NULL DEFAULT 'default', + entity_id BIGINT, + op_name TEXT NOT NULL DEFAULT 'default', + comment TEXT, + deleted BOOLEAN NOT NULL DEFAULT FALSE, + created_by TEXT NOT NULL DEFAULT 'default', + created_time TIMESTAMP NOT NULL DEFAULT now(), + last_modified_by TEXT DEFAULT '', + last_modified_time TIMESTAMP DEFAULT now() +); +CREATE INDEX audit_last_modified_time_index + ON audit (last_modified_time); + +CREATE SEQUENCE cluster_id_seq + INCREMENT 1 + START 1; +CREATE TABLE cluster ( + id BIGINT NOT NULL DEFAULT nextval('cluster_id_seq') PRIMARY KEY, + cluster_name TEXT NOT NULL DEFAULT '', + app_id TEXT NOT NULL DEFAULT '', + parent_cluster_id BIGINT NOT NULL DEFAULT 0, + deleted BOOLEAN NOT NULL DEFAULT FALSE, + created_by TEXT NOT NULL DEFAULT '', + created_time TIMESTAMP NOT NULL DEFAULT now(), + last_modified_by TEXT DEFAULT '', + last_modified_time TIMESTAMP DEFAULT now() +); +CREATE INDEX cluster_app_id_cluster_name_index + ON cluster (app_id, cluster_name); +CREATE INDEX cluster_parent_cluster_id_index + ON cluster (parent_cluster_id); +CREATE INDEX cluster_last_modified_time_index + ON cluster (last_modified_time); + +CREATE SEQUENCE commit_id_seq + INCREMENT 1 + START 1; +CREATE TABLE commit ( + id BIGINT NOT NULL DEFAULT nextval('commit_id_seq') PRIMARY KEY, + change_sets TEXT NOT NULL, + app_id TEXT NOT NULL DEFAULT 'default', + cluster_name TEXT NOT NULL DEFAULT 'default', + namespace_name TEXT NOT NULL DEFAULT 'default', + comment TEXT, + deleted BOOLEAN NOT NULL DEFAULT FALSE, + created_by TEXT NOT NULL DEFAULT 'default', + created_time TIMESTAMP NOT NULL DEFAULT now(), + last_modified_by TEXT DEFAULT '', + last_modified_time TIMESTAMP DEFAULT now() +); +CREATE INDEX commit_app_id_index + ON commit (app_id); +CREATE INDEX commit_cluster_name_index + ON commit (cluster_name); +CREATE INDEX commit_namespace_name_index + ON commit (namespace_name); +CREATE INDEX commit_last_modified_time_index + ON commit (last_modified_time); + +CREATE SEQUENCE gray_release_rule_id_seq + INCREMENT 1 + START 1; +CREATE TABLE gray_release_rule ( + id BIGINT NOT NULL DEFAULT nextval('gray_release_rule_id_seq') PRIMARY KEY, + app_id TEXT NOT NULL DEFAULT 'default', + cluster_name TEXT NOT NULL DEFAULT 'default', + namespace_name TEXT NOT NULL DEFAULT 'default', + branch_name TEXT NOT NULL DEFAULT 'default', + rules TEXT NOT NULL DEFAULT '[]', + release_id BIGINT NOT NULL DEFAULT 0, + branch_status SMALLINT DEFAULT 1, + deleted BOOLEAN NOT NULL DEFAULT FALSE, + created_by TEXT NOT NULL DEFAULT 'default', + created_time TIMESTAMP NOT NULL DEFAULT now(), + last_modified_by TEXT DEFAULT '', + last_modified_time TIMESTAMP DEFAULT now() +); +CREATE INDEX gray_release_rule_app_id_cluster_name_namespace_name_index + ON gray_release_rule (app_id, cluster_name, namespace_name); +CREATE INDEX gray_release_rule_last_modified_time_index + ON gray_release_rule (last_modified_time); + +CREATE SEQUENCE instance_id_seq + INCREMENT 1 + START 1; +CREATE TABLE instance ( + id BIGINT NOT NULL DEFAULT nextval('instance_id_seq') PRIMARY KEY, + app_id TEXT NOT NULL DEFAULT 'default', + cluster_name TEXT NOT NULL DEFAULT 'default', + data_center TEXT NOT NULL DEFAULT 'default', + ip TEXT NOT NULL DEFAULT '', + created_time TIMESTAMP NOT NULL DEFAULT now(), + last_modified_time TIMESTAMP DEFAULT now(), + UNIQUE (app_id, cluster_name, ip, data_center) +); +CREATE INDEX instance_ip_index + ON instance (ip); +CREATE INDEX instance_last_modified_time_index + ON instance (last_modified_time); + +CREATE SEQUENCE instance_config_id_seq + INCREMENT 1 + START 1; +CREATE TABLE instance_config ( + id BIGINT NOT NULL DEFAULT nextval('instance_config_id_seq') PRIMARY KEY, + instance_id BIGINT, + config_app_id TEXT NOT NULL DEFAULT 'default', + config_cluster_name TEXT NOT NULL DEFAULT 'default', + config_namespace_name TEXT NOT NULL DEFAULT 'default', + release_key TEXT NOT NULL DEFAULT '', + release_delivery_time TIMESTAMP, + created_time TIMESTAMP NOT NULL DEFAULT now(), + last_modified_time TIMESTAMP DEFAULT now(), + UNIQUE (instance_id, config_app_id, config_namespace_name) +); +CREATE INDEX instance_config_config_app_id_config_cluster_name_config_namespace_name_last_modified_time_index + ON instance_config (config_app_id, config_cluster_name, config_namespace_name, last_modified_time); +CREATE INDEX instance_config_release_key_index + ON instance_config (release_key); +CREATE INDEX instance_config_last_modified_time_index + ON instance_config (last_modified_time); + +CREATE SEQUENCE item_id_seq + INCREMENT 1 + START 1; +CREATE TABLE item ( + id BIGINT NOT NULL DEFAULT nextval('item_id_seq') PRIMARY KEY, + namespace_id BIGINT NOT NULL DEFAULT 0, + key TEXT NOT NULL DEFAULT 'default', + value TEXT NOT NULL, + comment TEXT DEFAULT '', + line_num BIGINT DEFAULT 0, + deleted BOOLEAN NOT NULL DEFAULT FALSE, + created_by TEXT NOT NULL DEFAULT 'default', + created_time TIMESTAMP NOT NULL DEFAULT now(), + last_modified_by TEXT DEFAULT '', + last_modified_time TIMESTAMP DEFAULT now() +); +CREATE INDEX item_namespace_id_index + ON item (namespace_id); +CREATE INDEX item_last_modified_time_index + ON item (last_modified_time); + +CREATE SEQUENCE namespace_id_seq + INCREMENT 1 + START 1; +CREATE TABLE namespace ( + id BIGINT NOT NULL DEFAULT nextval('namespace_id_seq') PRIMARY KEY, + app_id TEXT NOT NULL DEFAULT 'default', + cluster_name TEXT NOT NULL DEFAULT 'default', + namespace_name TEXT NOT NULL DEFAULT 'default', + deleted BOOLEAN NOT NULL DEFAULT FALSE, + created_by TEXT NOT NULL DEFAULT 'default', + created_time TIMESTAMP NOT NULL DEFAULT now(), + last_modified_by TEXT DEFAULT '', + last_modified_time TIMESTAMP DEFAULT now() +); +CREATE INDEX namespace_app_id_cluster_name_namespace_name_index + ON namespace (app_id, cluster_name, namespace_name); +CREATE INDEX namespace_namespace_name_index + ON namespace (namespace_name); +CREATE INDEX namespace_last_modified_time_index + ON namespace (last_modified_time); + +CREATE SEQUENCE namespace_lock_id_seq + INCREMENT 1 + START 1; +CREATE TABLE namespace_lock ( + id BIGINT NOT NULL DEFAULT nextval('namespace_lock_id_seq') PRIMARY KEY, + namespace_id BIGINT NOT NULL DEFAULT 0, + deleted BOOLEAN NOT NULL DEFAULT FALSE, + created_by TEXT NOT NULL DEFAULT 'default', + created_time TIMESTAMP NOT NULL DEFAULT now(), + last_modified_by TEXT DEFAULT 'default', + last_modified_time TIMESTAMP DEFAULT now(), + UNIQUE (namespace_id) +); +CREATE INDEX namespace_lock_last_modified_time_index + ON namespace_lock (last_modified_time); + +CREATE SEQUENCE release_id_seq + INCREMENT 1 + START 1; +CREATE TABLE release ( + id BIGINT NOT NULL DEFAULT nextval('release_id_seq') PRIMARY KEY, + release_key TEXT NOT NULL DEFAULT '', + release_name TEXT NOT NULL DEFAULT 'default', + comment TEXT, + app_id TEXT NOT NULL DEFAULT 'default', + cluster_name TEXT NOT NULL DEFAULT 'default', + namespace_name TEXT NOT NULL DEFAULT 'default', + configurations TEXT NOT NULL, + abandoned BOOLEAN NOT NULL DEFAULT FALSE, + deleted BOOLEAN NOT NULL DEFAULT FALSE, + created_by TEXT NOT NULL DEFAULT 'default', + created_time TIMESTAMP NOT NULL DEFAULT now(), + last_modified_by TEXT DEFAULT '', + last_modified_time TIMESTAMP DEFAULT now() +); +CREATE INDEX release_release_key_index + ON release (release_key); +CREATE INDEX release_app_id_cluster_name_namespace_name_index + ON release (app_id, cluster_name, namespace_name); +CREATE INDEX release_last_modified_time_index + ON release (last_modified_time); + +CREATE SEQUENCE release_history_id_seq + INCREMENT 1 + START 1; +CREATE TABLE release_history ( + id BIGINT NOT NULL DEFAULT nextval('release_history_id_seq') PRIMARY KEY, + app_id TEXT NOT NULL DEFAULT 'default', + cluster_name TEXT NOT NULL DEFAULT 'default', + namespace_name TEXT NOT NULL DEFAULT 'default', + branch_name TEXT NOT NULL DEFAULT 'default', + release_id BIGINT NOT NULL DEFAULT 0, + previous_release_id BIGINT NOT NULL DEFAULT 0, + operation SMALLINT NOT NULL DEFAULT 0, + operation_context TEXT NOT NULL, + deleted BOOLEAN NOT NULL DEFAULT FALSE, + created_by TEXT NOT NULL DEFAULT 'default', + created_time TIMESTAMP NOT NULL DEFAULT now(), + last_modified_by TEXT DEFAULT '', + last_modified_time TIMESTAMP DEFAULT now() +); +CREATE INDEX release_history_app_id_cluster_name_namespace_name_branch_name_index + ON release_history (app_id, cluster_name, namespace_name, branch_name); +CREATE INDEX release_history_release_id_index + ON release_history (release_id); +CREATE INDEX release_history_last_modified_time_index + ON release_history (last_modified_time); + +CREATE SEQUENCE release_message_id_seq + INCREMENT 1 + START 1; +CREATE TABLE release_message ( + id BIGINT NOT NULL DEFAULT nextval('release_message_id_seq') PRIMARY KEY, + message TEXT NOT NULL DEFAULT '', + last_modified_time TIMESTAMP DEFAULT now() +); +CREATE INDEX release_message_message_index + ON release_message (message); +CREATE INDEX release_message_last_modified_time_index + ON release_message (last_modified_time); + +CREATE SEQUENCE server_config_id_seq + INCREMENT 1 + START 1; +CREATE TABLE server_config ( + id BIGINT NOT NULL DEFAULT nextval('server_config_id_seq') PRIMARY KEY, + key TEXT NOT NULL DEFAULT 'default', + cluster TEXT NOT NULL DEFAULT 'default', + value TEXT NOT NULL DEFAULT 'default', + comment TEXT DEFAULT '', + deleted BOOLEAN NOT NULL DEFAULT FALSE, + created_by TEXT NOT NULL DEFAULT 'default', + created_time TIMESTAMP NOT NULL DEFAULT now(), + last_modified_by TEXT DEFAULT '', + last_modified_time TIMESTAMP DEFAULT now() +); +CREATE INDEX server_config_key_index + ON server_config (key); +CREATE INDEX server_config_last_modified_time_index + ON server_config (last_modified_time); + +--------------------------------------------------------------------------------------------- + + +INSERT INTO server_config (key, cluster, value, comment) +VALUES + ('eureka.service.url', 'default', 'http://127.0.0.1:8080/eureka/', 'Eureka服务Url,多个service以英文逗号分隔'), + ('namespace.lock.switch', 'default', 'false', '一次发布只能有一个人修改开关'), + ('item.key.length.limit', 'default', '1024', 'item key 最大长度限制'), + ('item.value.length.limit', 'default', '1024000', 'item value最大长度限制'), + ('config-service.cache.enabled', 'default', 'false', 'ConfigService是否开启缓存,开启后能提高性能,但是会增大内存消耗!'); diff --git a/scripts/sql/pg-portaldb.sql b/scripts/sql/pg-portaldb.sql new file mode 100644 index 00000000000..d5ad58579e1 --- /dev/null +++ b/scripts/sql/pg-portaldb.sql @@ -0,0 +1,277 @@ +CREATE SEQUENCE app_id_seq + INCREMENT 1 + START 1; +CREATE TABLE app ( + id BIGINT NOT NULL DEFAULT nextval('app_id_seq') PRIMARY KEY, + app_id TEXT NOT NULL DEFAULT 'default', + app_name TEXT NOT NULL DEFAULT 'default', + org_id TEXT NOT NULL DEFAULT 'default', + org_name TEXT NOT NULL DEFAULT 'default', + owner_name TEXT NOT NULL DEFAULT 'default', + owner_email TEXT NOT NULL DEFAULT 'default', + deleted BOOLEAN NOT NULL DEFAULT FALSE, + created_by TEXT NOT NULL DEFAULT 'default', + created_time TIMESTAMP NOT NULL DEFAULT now(), + last_modified_by TEXT DEFAULT '', + last_modified_time TIMESTAMP DEFAULT now() +); +CREATE INDEX app_app_id_index + ON app (app_id); +CREATE INDEX app_app_name_index + ON app (app_name); +CREATE INDEX app_last_modified_time_index + ON app (last_modified_time); + +CREATE SEQUENCE app_namespace_id_seq + INCREMENT 1 + START 1; +CREATE TABLE app_namespace ( + id BIGINT NOT NULL DEFAULT nextval('app_namespace_id_seq') PRIMARY KEY, + namespace_name TEXT NOT NULL DEFAULT '', + app_id TEXT NOT NULL DEFAULT '', + format TEXT NOT NULL DEFAULT 'properties', + shared BOOLEAN NOT NULL DEFAULT FALSE, + comment TEXT NOT NULL DEFAULT '', + deleted BOOLEAN NOT NULL DEFAULT FALSE, + created_by TEXT NOT NULL DEFAULT '', + created_time TIMESTAMP NOT NULL DEFAULT now(), + last_modified_by TEXT DEFAULT '', + last_modified_time TIMESTAMP DEFAULT now() +); +CREATE INDEX app_namespace_app_id_index + ON app_namespace (app_id); +CREATE INDEX app_namespace_namespace_name_app_id_index + ON app_namespace (namespace_name, app_id); +CREATE INDEX app_namespace_last_modified_time_index + ON app_namespace (last_modified_time); + +CREATE SEQUENCE consumer_id_seq + INCREMENT 1 + START 1; +CREATE TABLE consumer ( + id BIGINT NOT NULL DEFAULT nextval('consumer_id_seq') PRIMARY KEY, + app_id TEXT NOT NULL DEFAULT 'default', + consumer_name TEXT NOT NULL DEFAULT 'default', + org_id TEXT NOT NULL DEFAULT 'default', + org_name TEXT NOT NULL DEFAULT 'default', + owner_name TEXT NOT NULL DEFAULT 'default', + owner_email TEXT NOT NULL DEFAULT 'default', + deleted BOOLEAN NOT NULL DEFAULT FALSE, + created_by TEXT NOT NULL DEFAULT 'default', + created_time TIMESTAMP NOT NULL DEFAULT now(), + last_modified_by TEXT DEFAULT '', + last_modified_time TIMESTAMP DEFAULT now() +); +CREATE INDEX consumer_app_id_index + ON consumer (app_id); +CREATE INDEX consumer_last_modified_time_index + ON consumer (last_modified_time); + +CREATE SEQUENCE consumer_audit_id_seq + INCREMENT 1 + START 1; +CREATE TABLE consumer_audit ( + id BIGINT NOT NULL DEFAULT nextval('consumer_audit_id_seq') PRIMARY KEY, + consumer_id BIGINT, + uri TEXT NOT NULL DEFAULT '', + method TEXT NOT NULL DEFAULT '', + created_time TIMESTAMP NOT NULL DEFAULT now(), + last_modified_time TIMESTAMP DEFAULT now() +); +CREATE INDEX consumer_audit_consumer_id_index + ON consumer_audit (consumer_id); +CREATE INDEX consumer_audit_last_modified_time_index + ON consumer_audit (last_modified_time); + +CREATE SEQUENCE consumer_role_id_seq + INCREMENT 1 + START 1; +CREATE TABLE consumer_role ( + id BIGINT NOT NULL DEFAULT nextval('consumer_role_id_seq') PRIMARY KEY, + consumer_id BIGINT, + role_id BIGINT, + deleted BOOLEAN NOT NULL DEFAULT FALSE, + created_by TEXT NOT NULL DEFAULT '', + created_time TIMESTAMP NOT NULL DEFAULT now(), + last_modified_by TEXT DEFAULT '', + last_modified_time TIMESTAMP DEFAULT now() +); +CREATE INDEX consumer_role_consumer_id_role_id_index + ON consumer_role (consumer_id, role_id); +CREATE INDEX consumer_role_role_id_index + ON consumer_role (role_id); +CREATE INDEX consumer_role_last_modified_time_index + ON consumer_role (last_modified_time); + +CREATE SEQUENCE consumer_token_id_seq + INCREMENT 1 + START 1; +CREATE TABLE consumer_token ( + id BIGINT NOT NULL DEFAULT nextval('consumer_token_id_seq') PRIMARY KEY, + consumer_id BIGINT, + token TEXT NOT NULL DEFAULT '', + expires TIMESTAMP NOT NULL DEFAULT '2099-12-31 23:59:59' :: TIMESTAMP, + deleted BOOLEAN NOT NULL DEFAULT FALSE, + created_by TEXT NOT NULL DEFAULT 'default', + created_time TIMESTAMP NOT NULL DEFAULT now(), + last_modified_by TEXT DEFAULT '', + last_modified_time TIMESTAMP DEFAULT now(), + UNIQUE (token) +); +CREATE INDEX consumer_token_last_modified_time_index + ON consumer_token (last_modified_time); + +CREATE SEQUENCE favorite_id_seq + INCREMENT 1 + START 1; +CREATE TABLE favorite ( + id BIGINT NOT NULL DEFAULT nextval('favorite_id_seq') PRIMARY KEY, + user_id TEXT NOT NULL DEFAULT 'default', + app_id TEXT NOT NULL DEFAULT 'default', + favorite_position BIGINT NOT NULL DEFAULT 10000, + deleted BOOLEAN NOT NULL DEFAULT FALSE, + created_by TEXT NOT NULL DEFAULT 'default', + created_time TIMESTAMP NOT NULL DEFAULT now(), + last_modified_by TEXT DEFAULT '', + last_modified_time TIMESTAMP DEFAULT now() +); +CREATE INDEX favorite_user_id_index + ON favorite (user_id); +CREATE INDEX favorite_app_id_index + ON favorite (app_id); +CREATE INDEX favorite_last_modified_time_index + ON favorite (last_modified_time); + +CREATE SEQUENCE permission_id_seq + INCREMENT 1 + START 1; +CREATE TABLE permission ( + id BIGINT NOT NULL DEFAULT nextval('permission_id_seq') PRIMARY KEY, + permission_type TEXT NOT NULL DEFAULT '', + target_id TEXT NOT NULL DEFAULT '', + deleted BOOLEAN NOT NULL DEFAULT FALSE, + created_by TEXT NOT NULL DEFAULT '', + created_time TIMESTAMP NOT NULL DEFAULT now(), + last_modified_by TEXT DEFAULT '', + last_modified_time TIMESTAMP DEFAULT now() +); +CREATE INDEX permission_permission_type_target_id_index + ON permission (permission_type, target_id); +CREATE INDEX permission_last_modified_time_index + ON permission (last_modified_time); + +CREATE SEQUENCE role_id_seq + INCREMENT 1 + START 1; +CREATE TABLE role ( + id BIGINT NOT NULL DEFAULT nextval('role_id_seq') PRIMARY KEY, + role_name TEXT NOT NULL DEFAULT '', + deleted BOOLEAN NOT NULL DEFAULT FALSE, + created_by TEXT NOT NULL DEFAULT 'default', + created_time TIMESTAMP NOT NULL DEFAULT now(), + last_modified_by TEXT DEFAULT '', + last_modified_time TIMESTAMP DEFAULT now() +); +CREATE INDEX role_role_name_index + ON role (role_name); +CREATE INDEX role_last_modified_time_index + ON role (last_modified_time); + +CREATE SEQUENCE role_permission_id_seq + INCREMENT 1 + START 1; +CREATE TABLE role_permission ( + id BIGINT NOT NULL DEFAULT nextval('role_permission_id_seq') PRIMARY KEY, + role_id BIGINT, + permission_id BIGINT, + deleted BOOLEAN NOT NULL DEFAULT FALSE, + created_by TEXT NOT NULL DEFAULT '', + created_time TIMESTAMP NOT NULL DEFAULT now(), + last_modified_by TEXT DEFAULT '', + last_modified_time TIMESTAMP DEFAULT now() +); +CREATE INDEX role_permission_role_id_index + ON role_permission (role_id); +CREATE INDEX role_permission_permission_id_index + ON role_permission (permission_id); +CREATE INDEX role_permission_last_modified_time_index + ON role_permission (last_modified_time); + +CREATE SEQUENCE server_config_id_seq + INCREMENT 1 + START 1; +CREATE TABLE server_config ( + id BIGINT NOT NULL DEFAULT nextval('server_config_id_seq') PRIMARY KEY, + key TEXT NOT NULL DEFAULT 'default', + value TEXT NOT NULL DEFAULT 'default', + comment TEXT DEFAULT '', + deleted BOOLEAN NOT NULL DEFAULT FALSE, + created_by TEXT NOT NULL DEFAULT 'default', + created_time TIMESTAMP NOT NULL DEFAULT now(), + last_modified_by TEXT DEFAULT '', + last_modified_time TIMESTAMP DEFAULT now() +); +CREATE INDEX server_config_key_index + ON server_config (key); +CREATE INDEX server_config_last_modified_time_index + ON server_config (last_modified_time); + +CREATE SEQUENCE user_role_id_seq + INCREMENT 1 + START 1; +CREATE TABLE user_role ( + id BIGINT NOT NULL DEFAULT nextval('user_role_id_seq') PRIMARY KEY, + user_id TEXT DEFAULT '', + role_id BIGINT, + deleted BOOLEAN NOT NULL DEFAULT FALSE, + created_by TEXT NOT NULL DEFAULT '', + created_time TIMESTAMP NOT NULL DEFAULT now(), + last_modified_by TEXT DEFAULT '', + last_modified_time TIMESTAMP DEFAULT now() +); +CREATE INDEX user_role_user_id_role_id_index + ON user_role (user_id, role_id); +CREATE INDEX user_role_role_id_index + ON user_role (role_id); +CREATE INDEX user_role_last_modified_time_index + ON user_role (last_modified_time); + +CREATE SEQUENCE users_id_seq + INCREMENT 1 + START 1; +CREATE TABLE users ( + id BIGINT NOT NULL DEFAULT nextval('users_id_seq') PRIMARY KEY, + username TEXT NOT NULL DEFAULT 'default', + password TEXT NOT NULL DEFAULT 'default', + email TEXT NOT NULL DEFAULT 'default', + enabled BOOLEAN NOT NULL +); + +CREATE SEQUENCE authorities_id_seq + INCREMENT 1 + START 1; +CREATE TABLE authorities ( + id BIGINT NOT NULL DEFAULT nextval('authorities_id_seq') PRIMARY KEY, + username TEXT NOT NULL, + authority TEXT NOT NULL +); + +--------------------------------------------------------------------------------------------- + + +INSERT INTO server_config (key, value, comment) +VALUES + ('apollo.portal.envs', 'dev', '可支持的环境列表'), + ('organizations', '[{"orgId":"gdmp","orgName":"gdmp"}]', '部门列表'), + ('superAdmin', 'apollo', 'Portal超级管理员'), + ('api.readTimeout', '10000', 'http接口read timeout'), + ('consumer.token.salt', 'someSalt', 'consumer token salt'), + ('admin.createPrivateNamespace.switch', 'false', '是否允许项目管理员创建私有namespace'); + +INSERT INTO users (username, password, email, enabled) +VALUES + ('apollo', '$2a$10$7r20uS.BQ9uBpf3Baj3uQOZvMVvB1RN3PYoKE94gtz2.WAOuiiwXS', 'apollo@gridsum.com', TRUE); + +INSERT INTO authorities (username, authority) +VALUES + ('apollo', 'ROLE_user');