Data Generator is a relatively new feature, launching last year as part of the APEX 22.1 update. This new addition provides the developer with a built-in solution for creating customised sample data to aid development and testing.
The introduction of Data Generator was one of the many recent improvements that fall neatly in place with the ever-expanding line of developer utilities, which aim to increase the quality and efficiency of the APEX development experience.
Data Generator is under the 'utilities' section of the SQL Workshop. Any previously created blueprints are stored here. These can all be edited, exported, and used multiple times to re-generate data. For building a new sample data set, you have the option to create a new blueprint.
Data Generator works using blueprint files. Blueprints are JSON files that contain all the information on how the sample data should be created, including the tables, columns, and data sources.
Thankfully, we do not need to write blueprint files from scratch. Instead, Data Generator contains a blueprint designer that guides us through building blueprints based on one of the following options:
Choosing any of these options will always take you to the blueprint designer page.
Blueprint designer is where you will define the structure and attributes of the data to be generated based on tables, columns, and data sources.
If you are building a blueprint based on existing tables, the blueprint designer will attempt to make some intelligent decisions on the types of data to use and the source of the data. For example, if a chosen table has a foreign key, the blueprint designer will create a custom data source based on the existing related table. It will then use the primary key column from this source to generate the data for the foreign key column ensuring relational integrity maintains between the two.
If you want to choose your data source for a column, the following options are available:
Depending on the data type and source, some further attributes can be set at the column level, including number precision, format mask, whether a value must be required (and if not, what percentage should be null), maximum length, and multi-value options. When working with existing tables, the blueprint designer will again make some decisions for you here to reduce the likeliness of errors. It will populate the maximum length values to match that of the target column, and if a column has a not null constraint, it will mark the blueprint data as required for that column. Of course, you are also free to change any of these if needed.
These few points are worth considering before you complete your blueprint:
Once you are happy with your blueprint, you can save and export it or preview and generate your sample data.
The output of your sample data can be generated to files in several formats – JSON, CSV, or SQL (inserts). CSV outputs where multiple tables are used will produce a ZIP file containing a CSV file for each table.
When a blueprint is based on existing tables, there will be the additional option to insert the generated data straight into the database. There will be the choice of either using regular insert into (if any row fails, it skips to the next) or fast insert into (if a single row fails, no data will be inserted).
The range of development tools in APEX continues to grow, with Data Generator proving itself as an excellent addition to the collection. Having built-in functionality to create sample data takes Data Generator the extra mile by opening up the ability to directly interact with the database, whether building blueprints based on existing tables, using data sources or inserting generated data directly into the database.
Data Generator and the blueprint designer present a level of versatility that will cater to almost any sample data need whilst maintaining simplicity in understanding and usage. Hopefully, this is a utility that will continue to expand and improve with even more enhancements in the future.
For more information, check out our APEX services, and if you liked this blog, check out our other APEX blogs here.