Skip to content

Add section about PostgreSQL dependency #4376

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 20, 2025
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
19 changes: 9 additions & 10 deletions articles/control-center/database/flyway-migrations.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ order: 30

= Flyway Migrations

Control Center provides a simple way to set up Flyway migrations to initialize your database. This guide walks you through the steps to configure Flyway migrations for your Vaadin application using Control Center.
Control Center provides a simple way to set up Flyway migrations to initialize a database. This guide walks through the steps to configure Flyway migrations for a Vaadin application using Control Center.


== Control Center Starter

If you haven't already done so, add the Control Center Starter to your project. You also need to ensure that you have the Flyway PostgreSQL dependency in your project.
Add the Control Center Starter to your project if it isn't already. Ensure that the Flyway PostgreSQL dependency is also included in your project.

.pom.xml
[source,xml]
Expand All @@ -26,21 +26,20 @@ If you haven't already done so, add the Control Center Starter to your project.
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-database-postgresql</artifactId>
<version>11.7.2</version>
<scope>runtime</scope>
</dependency>
----

Once these dependencies are added and the Database feature is enabled, any migrations you create are automatically detected and applied to your database when the application starts.
Once these dependencies are added and the Database feature is enabled, any migrations found in the migration directory are automatically detected and applied to the database when the application starts.

For more information about how to setup Flyway in your application, see the <<{articles}/building-apps/forms-data/add-flyway#,Add Flyway>> page.
For more information about how to setup Flyway in an application, see the <<{articles}/building-apps/forms-data/add-flyway#,Add Flyway>> page.

NOTE: The Database feature must be <<../database#provisioning-a-database,enabled>> in order for Flyway migrations to be applied to the Control Center-managed database. If you have not already enabled the Database feature, you can do so during the deployment of your application or for an application that is already deployed.
NOTE: The Database feature must be <<../database#provisioning-a-database#,enabled>> in order for Flyway migrations to be applied to the Control Center-managed database. If the Database feature is not already enabled, it can be done during the deployment of an application or for an application that is already deployed.


== Migration Files

Flyway migrations are SQL scripts that define the changes to be applied to your database schema. These scripts should be placed in the `src/main/resources/db/migration` directory of your project. The naming convention for migration files is `V<version>__<description>.sql`, where `<version>` is a version number and `<description>` is a brief description of the migration.
Flyway migrations are SQL scripts that define the changes to be applied to a database schema. These scripts should be placed in the `src/main/resources/db/migration` directory of your project. The naming convention for migration files is `V<version>__<description>.sql`, where `<version>` is a version number and `<description>` is a brief description of the migration.

For example, a migration file to create a `users` table might be named `V1__Create_users_table.sql`. The contents of the file could look like this:

Expand All @@ -54,21 +53,21 @@ CREATE TABLE users (
INSERT INTO users (username, password) VALUES ('admin', 'admin');
----

You can create multiple migration files, and Flyway applies them in order based on their version numbers. Ideally, each migration file should contain a single change to the database schema, such as creating a table, adding a column, or modifying data.
Multiple migration files can be created, and Flyway applies them in order based on their version numbers. Ideally, each migration file should contain a single change to the database schema, such as creating a table, adding a column, or modifying data.

More information about Flyway migration files can be found in the https://flywaydb.org/documentation/[Flyway documentation].


== Viewing Migration Status

You can view the status of your Flyway migrations in the Control Center UI.
You can view the status of Flyway migrations in the Control Center UI.

To view the details of the applied migrations, first select the relevant application from the [guilabel]*Application Selector*, as shown in the screenshot here.

[.device]
image::/images/app-selector.png[Application Selector]

Navigate to the [guilabel]*Database* section and select [guilabel]*Migrations*. This displays a list of all applied migrations, including their version numbers and descriptions. You can also see the status of each migration, indicating whether it was successful or failed. If a migration fails, you should review the migration scripts for errors and redeploy the application when they are fixed.
Navigate to the [guilabel]*Database* section and select [guilabel]*Migrations*. This displays a list of all applied migrations, including their version numbers and descriptions. It also shows the status of each migration, indicating whether it was successful or failed. If a migration fails, review the migration scripts for errors and redeploy the application when they are fixed.

[.device]
image::/images/database-migrations.png[Database Migrations]
24 changes: 20 additions & 4 deletions articles/control-center/database/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,31 @@

= [since:com.vaadin:vaadin@V24.8]#Database#

Control Center provides a simple way to provision a database for your Vaadin application. It also allows you to manage database migrations and backups. These features allow you to easily set up and maintain a database for your application, ensuring that your data is always safe and up to date.
Control Center provides a simple way to provision a database for a Vaadin application. It also allows you to manage database migrations and backups. These features allow easy setup and maintenance of a database for an application, ensuring that data is always safe and up to date.


== PostgreSQL

Control Center uses PostgreSQL as the database for deployed applications. This requires including the PostgreSQL JDBC driver to be included in the project dependencies. For Maven projects, add the following dependency to your `pom.xml` file:

.pom.xml
[source,xml]
----
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
----


== Provisioning a Database

You can enable the Database feature either during the deployment of your application or for an application that is already deployed. When enabled, Control Center automatically provisions a dedicated PostgreSQL database exclusively for that application. If your application is configured to use a Spring datasource, the necessary connection details are set up automatically.
The Database feature can be enabled either during the deployment of an application or for an application that is already deployed. When enabled, Control Center automatically provisions a dedicated PostgreSQL database exclusively for that application. If the application is configured to use a Spring datasource, the necessary connection details are set up automatically.

Check failure on line 31 in articles/control-center/database/index.adoc

View workflow job for this annotation

GitHub Actions / lint

[vale] reported by reviewdog 🐶 [Vale.Spelling] Did you really mean 'datasource'? Raw Output: {"message": "[Vale.Spelling] Did you really mean 'datasource'?", "location": {"path": "articles/control-center/database/index.adoc", "range": {"start": {"line": 31, "column": 301}}}, "severity": "ERROR"}


== Database Migrations

A database migration is a process that manages incremental, reversible changes to a database schema over time. Migrations allow you to evolve your database structure safely and predictably, ensuring that your application and its data remain consistent as requirements change.
A database migration is a process that manages incremental, reversible changes to a database schema over time. Migrations allow the evolution of a database structure safely and predictably, ensuring that an application and its data remain consistent as requirements change.

Control Center integrates with Flyway for managing database migrations. For more information about how to setup Flyway in your application, see the <<{articles}/building-apps/forms-data/add-flyway#,Add Flyway>> page. For more information about how to use Flyway migrations with Control Center, see the <<./flyway-migrations#,Flyway Migrations>> page.
Control Center integrates with Flyway for managing database migrations. For more information about how to setup Flyway in an application, see the <<{articles}/building-apps/forms-data/add-flyway#,Add Flyway>> page. For more information about how to use Flyway migrations with Control Center, see the <<./flyway-migrations#,Flyway Migrations>> page.