Skip to content

Commit

Permalink
Merge pull request #25932 from mshima/liquibase-fake-data
Browse files Browse the repository at this point in the history
add liquibaseGenerateFakeData property
  • Loading branch information
DanielFran authored Apr 23, 2024
2 parents 40ed9bf + e275070 commit aa70216
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
10 changes: 10 additions & 0 deletions generators/bootstrap-application/generator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@ describe(`generator - ${generator}`, () => {
"jpaGeneratedValueSequence": false,
"liquibaseDefaultValueAttributeName": undefined,
"liquibaseDefaultValueAttributeValue": undefined,
"liquibaseGenerateFakeData": true,
"loadColumnType": "\${uuidType}",
"nullable": true,
"path": [
Expand Down Expand Up @@ -422,6 +423,7 @@ describe(`generator - ${generator}`, () => {
"javaValueSample2": ""login2"",
"liquibaseDefaultValueAttributeName": undefined,
"liquibaseDefaultValueAttributeValue": undefined,
"liquibaseGenerateFakeData": true,
"loadColumnType": "string",
"maxlength": 50,
"nullable": false,
Expand Down Expand Up @@ -507,6 +509,7 @@ describe(`generator - ${generator}`, () => {
"javaValueSample2": ""firstName2"",
"liquibaseDefaultValueAttributeName": undefined,
"liquibaseDefaultValueAttributeValue": undefined,
"liquibaseGenerateFakeData": true,
"loadColumnType": "string",
"maxlength": 50,
"nullable": true,
Expand Down Expand Up @@ -591,6 +594,7 @@ describe(`generator - ${generator}`, () => {
"javaValueSample2": ""lastName2"",
"liquibaseDefaultValueAttributeName": undefined,
"liquibaseDefaultValueAttributeValue": undefined,
"liquibaseGenerateFakeData": true,
"loadColumnType": "string",
"maxlength": 50,
"nullable": true,
Expand Down Expand Up @@ -679,6 +683,7 @@ describe(`generator - ${generator}`, () => {
"javaValueSample2": ""email2"",
"liquibaseDefaultValueAttributeName": undefined,
"liquibaseDefaultValueAttributeValue": undefined,
"liquibaseGenerateFakeData": true,
"loadColumnType": "string",
"maxlength": 191,
"nullable": false,
Expand Down Expand Up @@ -764,6 +769,7 @@ describe(`generator - ${generator}`, () => {
"javaValueSample2": ""imageUrl2"",
"liquibaseDefaultValueAttributeName": undefined,
"liquibaseDefaultValueAttributeValue": undefined,
"liquibaseGenerateFakeData": true,
"loadColumnType": "string",
"maxlength": 256,
"nullable": true,
Expand Down Expand Up @@ -842,6 +848,7 @@ describe(`generator - ${generator}`, () => {
"javaFieldType": "Boolean",
"liquibaseDefaultValueAttributeName": undefined,
"liquibaseDefaultValueAttributeValue": undefined,
"liquibaseGenerateFakeData": true,
"loadColumnType": "boolean",
"nullable": true,
"path": [
Expand Down Expand Up @@ -925,6 +932,7 @@ describe(`generator - ${generator}`, () => {
"javaValueSample2": ""langKey2"",
"liquibaseDefaultValueAttributeName": undefined,
"liquibaseDefaultValueAttributeValue": undefined,
"liquibaseGenerateFakeData": true,
"loadColumnType": "string",
"maxlength": 10,
"nullable": true,
Expand Down Expand Up @@ -1213,6 +1221,7 @@ describe(`generator - ${generator}`, () => {
"jpaGeneratedValueSequence": false,
"liquibaseDefaultValueAttributeName": undefined,
"liquibaseDefaultValueAttributeValue": undefined,
"liquibaseGenerateFakeData": true,
"loadColumnType": "\${uuidType}",
"nullable": true,
"path": [
Expand Down Expand Up @@ -1554,6 +1563,7 @@ describe(`generator - ${generator}`, () => {
"jpaGeneratedValueSequence": false,
"liquibaseDefaultValueAttributeName": undefined,
"liquibaseDefaultValueAttributeValue": undefined,
"liquibaseGenerateFakeData": true,
"loadColumnType": "\${uuidType}",
"nullable": true,
"path": [
Expand Down
1 change: 1 addition & 0 deletions generators/liquibase/support/prepare-field.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ export default function prepareField(entity, field) {
columnRequired: data => data.nullable === false || (data.fieldValidate === true && data.fieldValidateRules.includes('required')),
nullable: data => !data.columnRequired,
loadColumnType: data => parseLiquibaseLoadColumnType(entity, data),
liquibaseGenerateFakeData: true,
});

return field;
Expand Down
1 change: 1 addition & 0 deletions generators/liquibase/support/relationship.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export function prepareRelationshipForLiquibase(entity, relationship) {
__override__: false,
columnDataType: data => data.otherEntity.columnType,
columnRequired: data => data.nullable === false || data.relationshipRequired,
liquibaseGenerateFakeData: data => data.columnRequired && data.persistableRelationship && !data.collection,
});

return relationship;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ let table = [];
// Generate CSV header
let header = [];
const fieldsToGenerate = [...allFields.filter(f => f.id), ...fields.filter(f => !f.id)];
const fieldsToGenerate = [...allFields.filter(f => f.id), ...fields.filter(f => !f.id)].filter(field => field.liquibaseGenerateFakeData);
for (field of fieldsToGenerate) {
header.push(field.columnName);
if (field.shouldCreateContentType) {
header.push(field.columnName + '_content_type');
}
}
for (relationship of relationships.filter(relationship => relationship.columnRequired && relationship.persistableRelationship && !relationship.collection)) {
for (relationship of relationships.filter(relationship => relationship.liquibaseGenerateFakeData)) {
const { joinColumnNames } = relationship;
header.push(joinColumnNames[0]);
}
Expand Down Expand Up @@ -57,7 +57,7 @@ for (lineNb = 0; lineNb < entity.fakeDataCount; lineNb++) {
}
}
for (relationship of relationships.filter(relationship => relationship.columnRequired && relationship.persistableRelationship && !relationship.collection)) {
for (relationship of relationships.filter(relationship => relationship.liquibaseGenerateFakeData)) {
const relationshipType = relationship.relationshipType;
const otherLiquibaseFakeData = relationship.otherEntity.liquibaseFakeData;
let relationshipRow = lineNb;
Expand Down

0 comments on commit aa70216

Please sign in to comment.