liveBook · Manning

Import.sql

As explained in Quarkus in Action

import.sql is a conventional SQL script that initializes relational database contents when a persistence connection is established.

import.sql is a SQL script placed in src/main/resources to prepopulate a relational database when Quarkus connects through Hibernate with Panache. It preserves initial development data while repository-backed services replace generated in-memory stubs. section 7.2.2

Use import.sql with these operational constraints:

  • Quarkus uses the script by default in development mode when the file exists. section 11.1.1
  • Production mode disables SQL-script loading by default; explicitly set quarkus.hibernate-orm.sql-load-script=import.sql to enable it. section 11.1.1
  • Treat the contents primarily as testing and development data unless production loading is deliberately configured. section 7.2.2

Prepopulate the car inventory

Create src/main/resources/import.sql with INSERT statements for the Car table, such as Mazda 6 with license plate ABC123 and Ford Mustang with license plate XYZ987.

Listing 7.16 Example import.sql file to prepopulate the database
INSERT INTO Car (licensePlateNumber, manufacturer, model)
 VALUES ('ABC123', 'Mazda', '6');
INSERT INTO Car (licensePlateNumber, manufacturer, model)
 VALUES ('XYZ987', 'Ford', 'Mustang');

Inspect the complete import.sql listing containing the two initial Car records. section 7.2.2

How Quarkus in Action covers it

How deep it goes
Explains file placement, execution timing, environment defaults, and an INSERT example, but not SQL loading internals.
Examples
Uses Car INSERT statements for Mazda and Ford inventory records, then verifies persisted rows in MySQL.
What it assumes
Assumes a Quarkus persistence connection and relational schema, while demonstrating the file location and basic INSERT format.
What you can do after
Operate Quarkus database initialization by creating import.sql and enabling its loading explicitly for production.
How it connects
Connects import.sql with Quarkus, Hibernate ORM, Panache, repositories, transactions, and relational databases.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Quarkus in Action. The section links point to the parts of the book it draws on.