1

I have a number of Jhipster apps to scaffold.

Creating the entities by typing in the name, fields and relationships is time consuming, boring and error prone when you have many tables.

Where is the SQL script to run against my database? The one that outputs a script which can be run as a batch file to create the entities programmatically.

Great product by the way.

Ribeye
  • 2,137
  • 3
  • 18
  • 25

2 Answers2

0

JHipster generates a Liquibase changelog, there is no SQL script (but it's basically the same, only it is database independant and easier to version).

What you would like is to script the generator: it does not exist yet.

Yeoman generators don't usually work that way: one good reason is that there is quite a lot of validation for each question, so it's much less error prone to answer them than to script them, normally.

Then, you have a specific use case as you want to auto generate several applications with the same code and database tables: I don't know the rational behind this, but you can understand that for a "normal" situation this would be considered a bad practice.

Julien Dubois
  • 3,678
  • 1
  • 20
  • 22
  • What I am facing is a robotic process of - create an entity in Jhipster for each table - create an attribute for each table column using the column name and type - create a relationship for each relationship defined in the Mysql database relationships Thats a lot of type "yo jhipster:entity....." etc when the inputs are clearly specified by the database schema. I am looking for a script to run against the db (presumably using SQL) and feeding it into one of the keyboard robots to drive Jhipster. That would not be a bad practice, would it? – Ribeye Oct 31 '14 at 14:13
  • OK, but still it's quite a specific use case. I'd like to have the ability to script the entity sub-generator: it wouldn't be very complicated to do (we auto-answer the questions, basically). It just doesn't exist yet. – Julien Dubois Nov 02 '14 at 17:40
  • Thanks Julien. I am thinking of trying with Robot for Java. Expect also looks like a good option. Unless you would like to suggest something else? – Ribeye Nov 03 '14 at 07:20
-1

I thought it is never too late for this. I read this post and tried out an auto-generation script, based on that post's instructions and the links in it, to generate my entities. My sample script below creates a "book" entity. Instructions:

  1. Create in the project directory, a batch file with extension .cmd and as content the script below.
  2. Open a Windows console (Console 1) with "cmd" command.
  3. CD to your JHipster project directory.
  4. Open a second console (Console 2).
  5. CD to your JHipster project directory as above.
  6. Run the script in Console 2.
  7. Immediately click the titlebar of Console 1, for it to get the focus.

You will see your book entity being created. From there you may manually edit an entity's JSON file and re-run (this time manually!!) the "yo jhipster:entity" command for that entity. You may put all your entities with all fields and relations in the script and enjoy the ride. It might be very useful if you have a UML tool produce a script like this.

The pings are to pause the input being send to the console windows with the focus, because the command "yo jhipster:entity" takes some time to present the first prompt and some times also the others.

@if (@CodeSection == @Batch) @then

@echo off

rem Use %SendKeys% to send keys to the keyboard buffer
set SendKeys=CScript //nologo //E:JScript "%~F0"
rem set SendKeys=CScript //nologo //E:JScript

rem Start the other program in the same Window
start "" /B cmd

ping -n 12 -w 1 127.0.0.1 > NUL
%SendKeys% "yo jhipster:entity book{ENTER}"
ping -n 2 -w 1 127.0.0.1 > NUL
%SendKeys% "{Y}{ENTER}"
ping -n 2 -w 1 127.0.0.1 > NUL
%SendKeys% "name{ENTER}"
ping -n 2 -w 1 127.0.0.1 > NUL
%SendKeys% "{ENTER}"
ping -n 2 -w 1 127.0.0.1 > NUL
%SendKeys% "{Y}{ENTER}"
ping -n 2 -w 1 127.0.0.1 > NUL
%SendKeys% " "
ping -n 2 -w 1 127.0.0.1 > NUL
%SendKeys% "{DOWN}"
ping -n 2 -w 1 127.0.0.1 > NUL
%SendKeys% " "
ping -n 2 -w 1 127.0.0.1 > NUL
%SendKeys% "{DOWN}"
ping -n 2 -w 1 127.0.0.1 > NUL
%SendKeys% " "
ping -n 2 -w 1 127.0.0.1 > NUL
%SendKeys% "{ENTER}"
ping -n 2 -w 1 127.0.0.1 > NUL
%SendKeys% "4{ENTER}"
ping -n 2 -w 1 127.0.0.1 > NUL
%SendKeys% "64{ENTER}"
ping -n 2 -w 1 127.0.0.1 > NUL
%SendKeys% "N{ENTER}"
ping -n 2 -w 1 127.0.0.1 > NUL
%SendKeys% "N{ENTER}"
ping -n 2 -w 1 127.0.0.1 > NUL
%SendKeys% "{ENTER}"

goto :EOF

@end

// JScript section

var WshShell = WScript.CreateObject("WScript.Shell");
WshShell.SendKeys(WScript.Arguments(0));
Community
  • 1
  • 1
Oshkosh1017
  • 109
  • 9