Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 77 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,15 @@ jobs:
cp .github/settings.xml ~/.m2/settings.xml
- name: Build and push server image
run: |
VERSION=$(cat VERSION | tr -d '[:space:]')
BUILD_VERSION="${VERSION}.${{ github.run_number }}"
FULL_VERSION="${BUILD_VERSION}-$(git rev-parse --short HEAD)"
mvn -B -Dmaven.test.skip=true clean package -pl flexmodel-server -am \
-Dflexmodel.version=${BUILD_VERSION} \
-Dquarkus.container-image.build=true \
-Dquarkus.container-image.push=true \
-Dquarkus.container-image.image=cjbi/flexmodel-server:latest \
-Dquarkus.container-image.image=cjbi/flexmodel-server:${BUILD_VERSION} \
-Dquarkus.container-image.additional-tags=latest,${VERSION},${FULL_VERSION},sha-${{ github.sha }} \
-Dquarkus.container-image.username=${{ secrets.DOCKER_USERNAME }} \
-Dquarkus.container-image.password=${{ secrets.DOCKER_PASSWORD }}

Expand All @@ -140,10 +145,15 @@ jobs:
cache-dependency-path: '**/pom.xml'
- name: Build and push server native image
run: |
VERSION=$(cat VERSION | tr -d '[:space:]')
BUILD_VERSION="${VERSION}.${{ github.run_number }}"
FULL_VERSION="${BUILD_VERSION}-$(git rev-parse --short HEAD)"
mvn -B -Dmaven.test.skip=true clean package -Pnative -pl flexmodel-server -am \
-Dflexmodel.version=${BUILD_VERSION} \
-Dquarkus.container-image.build=true \
-Dquarkus.container-image.push=true \
-Dquarkus.container-image.image=cjbi/flexmodel-server-native:latest \
-Dquarkus.container-image.image=cjbi/flexmodel-server-native:${BUILD_VERSION} \
-Dquarkus.container-image.additional-tags=latest,${VERSION},${FULL_VERSION},sha-${{ github.sha }} \
-Dquarkus.container-image.username=${{ secrets.DOCKER_USERNAME }} \
-Dquarkus.container-image.password=${{ secrets.DOCKER_PASSWORD }}

Expand All @@ -153,6 +163,13 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- name: Read version
id: version
run: |
VERSION=$(cat VERSION | tr -d '[:space:]')
echo "tag=${VERSION}.${{ github.run_number }}" >> $GITHUB_OUTPUT
echo "ver=${VERSION}" >> $GITHUB_OUTPUT
echo "full=${VERSION}.${{ github.run_number }}-${{ github.sha }}" >> $GITHUB_OUTPUT
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
- name: Log in to Docker Hub
Expand All @@ -165,23 +182,78 @@ jobs:
with:
context: flexmodel-functions-runtime
push: true
tags: cjbi/flexmodel-functions-runtime:latest
tags: |
cjbi/flexmodel-functions-runtime:latest
cjbi/flexmodel-functions-runtime:${{ steps.version.outputs.ver }}
cjbi/flexmodel-functions-runtime:${{ steps.version.outputs.tag }}
cjbi/flexmodel-functions-runtime:${{ steps.version.outputs.full }}
cjbi/flexmodel-functions-runtime:sha-${{ github.sha }}
cache-from: type=gha
cache-to: type=gha,mode=max

push-ui-image:
name: Push UI docker image
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
with:
submodules: 'recursive'
token: ${{ secrets.GITHUB_TOKEN }}
- name: Read version
id: version
run: |
VERSION=$(cat VERSION | tr -d '[:space:]')
echo "tag=${VERSION}.${{ github.run_number }}" >> $GITHUB_OUTPUT
echo "ver=${VERSION}" >> $GITHUB_OUTPUT
echo "full=${VERSION}.${{ github.run_number }}-${{ github.sha }}" >> $GITHUB_OUTPUT
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
- name: Log in to Docker Hub
uses: docker/login-action@v4
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and push UI image
uses: docker/build-push-action@v7
with:
context: flexmodel-ui
push: true
tags: |
cjbi/flexmodel-ui:latest
cjbi/flexmodel-ui:${{ steps.version.outputs.ver }}
cjbi/flexmodel-ui:${{ steps.version.outputs.tag }}
cjbi/flexmodel-ui:${{ steps.version.outputs.full }}
cjbi/flexmodel-ui:sha-${{ github.sha }}
cache-from: type=gha
cache-to: type=gha,mode=max

# deploy:
# name: Deploy to production
# runs-on: ubuntu-latest
# needs: [ push-server-image, push-ui-image, push-functions-runtime-image ]
# needs: [ push-server-image, push-functions-runtime-image, push-ui-image ]
# steps:
# - uses: actions/checkout@v5
# - name: Read version
# id: version
# run: echo "tag=$(cat VERSION | tr -d '[:space:]').${{ github.run_number }}" >> $GITHUB_OUTPUT
# - name: Deploy Docker Image
# uses: appleboy/ssh-action@master
# env:
# IMAGE_TAG: ${{ steps.version.outputs.tag }}
# with:
# host: ${{ secrets.HOST }}
# username: ${{ secrets.SSH_USER }}
# port: ${{ secrets.SSH_PORT }}
# key: ${{ secrets.SSH_KEY }}
# envs: IMAGE_TAG
# command_timeout: 10m
# script: |
# cd /opt/flexmodel-quickstarts/docker-compose
# docker-compose pull flexmodel-server flexmodel-ui flexmodel-functions-runtime
# docker pull cjbi/flexmodel-server:${IMAGE_TAG}
# docker pull cjbi/flexmodel-functions-runtime:${IMAGE_TAG}
# docker pull cjbi/flexmodel-ui:${IMAGE_TAG}
# docker tag cjbi/flexmodel-server:${IMAGE_TAG} cjbi/flexmodel-server:latest
# docker tag cjbi/flexmodel-functions-runtime:${IMAGE_TAG} cjbi/flexmodel-functions-runtime:latest
# docker tag cjbi/flexmodel-ui:${IMAGE_TAG} cjbi/flexmodel-ui:latest
# docker-compose up -d
# echo "Deployed version ${IMAGE_TAG}"
1 change: 1 addition & 0 deletions VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v0.0.1
2 changes: 1 addition & 1 deletion flexmodel-engine/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ try (Session session = sessionFactory.createSession("mySchema")) {
{
"objects": [
{
"type": "entity",
"type": "Entity",
"name": "User",
"comment": "用户表",
"fields": [
Expand Down
37 changes: 14 additions & 23 deletions flexmodel-engine/docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -339,31 +339,22 @@ EnumField statusField = new EnumField("status")
.setDefaultValue("PENDING");
```

#### 关系字段
#### 模型引用字段

```java
// 一对一关系
RelationField profileField = new RelationField("profile")
.setType(RelationField.Type.ONE_TO_ONE)
.setFrom("User")
.setTo("UserProfile")
.setForeignField("user_id");

// 一对多关系
RelationField ordersField = new RelationField("orders")
.setType(RelationField.Type.ONE_TO_MANY)
.setFrom("User")
.setTo("Order")
.setForeignField("user_id");

// 多对多关系
RelationField rolesField = new RelationField("roles")
.setType(RelationField.Type.MANY_TO_MANY)
.setFrom("User")
.setTo("Role")
.setJoinTable("user_roles")
.setJoinColumn("user_id")
.setInverseJoinColumn("role_id");
// 单选引用(一对一)
ModelRefField profileField = new ModelRefField("profile")
.setFrom("UserProfile")
.setLocalField("profileId")
.setForeignField("id");

// 多选引用(一对多)
ModelRefField ordersField = new ModelRefField("orders")
.setMultiple(true)
.setFrom("Order")
.setLocalField("userId")
.setForeignField("id");

```

### 异常处理
Expand Down
2 changes: 1 addition & 1 deletion flexmodel-engine/docs/flexmodel-codegen.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class ListApiDefinitionGenerator extends ApiDefinitionGenerator {
out.println "query MyListQuery( \$where: ${modelName}BoolExp) {"
out.println " ${modelName}(where: \$where) {"
context.getModelClass().getAllFields().each {
if (!it.isRelationField()) {
if (!it.isModelRefField()) {
out.println " ${it.fieldName}"
}
}
Expand Down
4 changes: 3 additions & 1 deletion flexmodel-engine/docs/flexmodel-core.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,9 @@ session.schema().createEntity("Student", entity -> entity
.addField(new IntField("age"))
.addField(new FloatField("score").setPrecision(5).setScale(2))
.addField(new EnumRefField("gender").setFrom("UserGender"))
.addField(new RelationField("studentClass")
.

addField(new ModelRefField("studentClass")
.setFrom("Classes")
.setLocalField("classId")
.setForeignField("id"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/
public enum JavaType {

RELATION(ScalarType.RELATION_TYPE, null, null, null),
MODEL_REF(ScalarType.MODEL_REF_TYPE, null, null, null),
STRING(STRING_TYPE, null, "String", "String"),
FLOAT(FLOAT_TYPE, null, "Double", "Double"),
INT(INT_TYPE, null, "Integer", "Integer"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import dev.flexmodel.model.EntityDefinition;
import dev.flexmodel.model.ModelDefinition;
import dev.flexmodel.model.field.EnumRefField;
import dev.flexmodel.model.field.RelationField;
import dev.flexmodel.model.field.ModelRefField;
import dev.flexmodel.model.field.TypedField;

import java.util.ArrayList;
Expand All @@ -19,7 +19,7 @@ public class ModelClass extends AbstractClass<ModelClass> {
private ModelField idField;
private final List<ModelField> basicFields = new ArrayList<>();
private final List<ModelField> enumFields = new ArrayList<>();
private final List<ModelField> relationFields = new ArrayList<>();
private final List<ModelField> modelRefFields = new ArrayList<>();
private final List<ModelField> allFields = new ArrayList<>();
private ModelDefinition original;

Expand Down Expand Up @@ -56,7 +56,7 @@ public static ModelClass buildModelClass(String replaceString, String packageNam
.setComment(field.getComment());

switch (field) {
case RelationField relationField -> {
case ModelRefField relationField -> {
String ftName = StringUtils.capitalize(
StringUtils.snakeToCamel(
replaceString != null ?
Expand All @@ -68,13 +68,13 @@ public static ModelClass buildModelClass(String replaceString, String packageNam
modelField.setTypePackage("java.util")
.setFullTypeName("java.util.List")
.setShortTypeName("List<" + ftName + ">")
.setRelationField(true);
.setModelRefField(true);
} else {
modelField.setTypePackage(null)
.setFullTypeName(modelField.getTypePackage() + "." + ftName)
.setShortTypeName(ftName)
.setRelationField(true);
modelClass.getRelationFields().add(modelField);
.setModelRefField(true);
modelClass.getModelRefFields().add(modelField);
}

}
Expand Down Expand Up @@ -150,8 +150,8 @@ public List<ModelField> getEnumFields() {
return enumFields;
}

public List<ModelField> getRelationFields() {
return relationFields;
public List<ModelField> getModelRefFields() {
return modelRefFields;
}

public List<ModelField> getAllFields() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class ModelField {
private String fullTypeName;
private boolean identity;
private boolean basicField;
private boolean relationField;
private boolean modelRefField;
private boolean enumField;
private Field original;

Expand Down Expand Up @@ -103,8 +103,8 @@ public ModelField setBasicField(boolean basicField) {
return this;
}

public boolean isRelationField() {
return relationField;
public boolean isModelRefField() {
return modelRefField;
}

public boolean isEnumField() {
Expand All @@ -116,8 +116,8 @@ public ModelField setEnumField(boolean enumField) {
return this;
}

public ModelField setRelationField(boolean relationField) {
this.relationField = relationField;
public ModelField setModelRefField(boolean relationField) {
this.modelRefField = relationField;
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ public void writeModel(PrintWriter out, GenerationContext context) {
out.println(" * " + field.getComment());
out.println(" */");
}
if (field.isRelationField()) {
out.println(" @ModelRelation");
}
if (field.isModelRefField()) {
out.println(" @ModelRef");
}
out.println(" @ModelField(\"" + field.getOriginal().getName() + "\")");
out.println(" private " + field.getShortTypeName() + " " + field.getVariableName() + ";");
}
Expand Down
20 changes: 10 additions & 10 deletions flexmodel-engine/flexmodel-codegen/src/test/resources/import.json
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,11 @@
}
],
"indexes": [],
"type": "entity"
"type": "Entity"
},
{
"name": "fs_datasource",
"type": "entity",
"type": "Entity",
"fields": [
{
"name": "name",
Expand Down Expand Up @@ -198,7 +198,7 @@
},
{
"name": "fs_api_log",
"type": "entity",
"type": "Entity",
"fields": [
{
"name": "id",
Expand Down Expand Up @@ -258,7 +258,7 @@
]
},
{
"type": "entity",
"type": "Entity",
"name": "Student",
"fields": [
{
Expand Down Expand Up @@ -315,7 +315,7 @@
},
{
"name": "studentDetail",
"type": "Relation",
"type": "ModelRef",
"modelName": "Student",
"unique": false,
"nullable": true,
Expand All @@ -329,7 +329,7 @@
"indexes": []
},
{
"type": "entity",
"type": "Entity",
"name": "StudentDetail",
"fields": [
{
Expand Down Expand Up @@ -363,7 +363,7 @@
},
{
"name": "LogLevel",
"type": "enum",
"type": "Enum",
"elements": [
"DEBUG",
"INFO",
Expand All @@ -374,7 +374,7 @@
},
{
"name": "UserGender",
"type": "enum",
"type": "Enum",
"elements": [
"UNKNOWN",
"MALE",
Expand All @@ -384,7 +384,7 @@
},
{
"name": "User_interest",
"type": "enum",
"type": "Enum",
"elements": [
"chang",
"tiao",
Expand Down Expand Up @@ -490,4 +490,4 @@
]
}
]
}
}
Loading