Schema Migration Flashcards

1
Q

What is Liquibase?

A

Liquibase is an open-source database version control and schema migration tool designed to help manage database changes across different environments.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

In what format are database changes defined in Liquibase?

A

Database changes in Liquibase are defined using a declarative “changeset” format, often written in XML or other formats.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What does a “changelog” represent in Liquibase?

A

A “changelog” in Liquibase is a file or set of files that contains a history of changes made to the database.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Name a few operations that can be included in Liquibase changesets.

A

Operations such as creating tables, adding columns, inserting data, and more can be included in Liquibase changesets.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How does Liquibase support version control for database schemas?

A

Liquibase enables version control by allowing developers to store their database changes in version-controlled files along with their application code.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Which build tools can Liquibase be integrated into?

A

Liquibase can be integrated into build tools such as Maven and Gradle, enabling automated database schema updates as part of the build process.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the purpose of a “changeset” in Liquibase?

A

A “changeset” in Liquibase is a unique identifier for an individual database change, containing the specifics of the change (e.g., creating a table, adding a column).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Example of a Liquibase changeset in XML format:

A

<changeSet>
<createTable>
<column>
<constraints></constraints>
</column>
<column></column>
<!-- Additional columns or constraints can be defined here -->
</createTable>
</changeSet>

Liquibase is widely used in DevOps and Continuous Integration (CI) environments to manage and automate database schema changes along with application code changes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is Flyway?

A

Flyway is an open-source database migration tool that simplifies the process of managing and applying incremental changes to database schemas.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How does Flyway organize database migrations?

A

Flyway organizes database migrations as a series of versioned SQL scripts or Java-based migrations that are applied in order.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is the purpose of a “baseline” in Flyway?

A

A “baseline” in Flyway is used to set a starting point for versioning an existing database, preventing the execution of earlier migrations when starting with an already existing database.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

In what scenarios is Flyway commonly used?

A

Flyway is commonly used in scenarios involving continuous integration, continuous delivery, and managing evolving database schemas in Agile development environments.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How does Flyway handle versioning of database changes?

A

Flyway uses a versioning system to keep track of which migrations have been applied to a database. Each migration is uniquely identified by a version number.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Can Flyway migrations be written in different scripting languages?

A

Yes, Flyway supports migrations written in various scripting languages such as SQL (Structured Query Language) or Java.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What integration options does Flyway provide?

A

Flyway can be easily integrated into build tools such as Maven, Gradle, and others, allowing for seamless automation of database migrations.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

How does Flyway handle rollbacks of database changes?

A

Flyway provides some support for rollbacks, allowing developers to undo specific migrations. However, manual intervention may be required for more complex rollbacks.

17
Q

Flyway Step 1: Set Up Maven Project

A

<dependencies>
<!-- Flyway Core -->
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
<version>7.15.0</version> <!-- Use the latest version -->
</dependency>

<!-- Your Database Driver (e.g., PostgreSQL) -->
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.2.24</version> <!-- Use the latest version -->
</dependency>
</dependencies>

18
Q

Flyway Step 2: Create Database Configuration

A

Create a flyway.conf file in your project’s src/main/resources directory with your database configuration:

flyway.url=jdbc:postgresql://your-database-host:5432/your-database
flyway.user=your-username
flyway.password=your-password

19
Q

Flyway Step 3: Write SQL Migration Scripts

A

Create SQL migration scripts in the src/main/resources/db/migration directory. For example, create V1__Create_Table.sql:

– db/migration/V1__Create_Table.sql
CREATE TABLE example_table (
id SERIAL PRIMARY KEY,
name VARCHAR(255) NOT NULL
);

20
Q

Flyway : Step 4: Java Application Entry Point

A

In your Java application, add a class with a main method to serve as the entry point. In this example, we’ll create FlywayApp.java:

import org.flywaydb.core.Flyway;

public class FlywayApp {

public static void main(String[] args) {
    // Create Flyway instance
    Flyway flyway = Flyway.configure().load();

    // Clean and migrate the database
    flyway.clean();
    flyway.migrate();
} }
21
Q

Flyway : Step 5: Run the Application

A

Run your Java application, and Flyway will automatically apply the database migrations.

This is a basic example, and you can explore additional Flyway features, such as handling different environments, managing schemas, and integrating with different build tools. Make sure to replace the placeholder values (e.g., database URL, username, password) with your actual database configuration.

22
Q

Liquibase: Step 1: Set Up Maven Project

A

<dependencies>
<!-- Liquibase Core -->
<dependency>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-core</artifactId>
<version>4.19.1</version> <!-- Use the latest version -->
</dependency>

<!-- Your Database Driver (e.g., PostgreSQL) -->
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.2.24</version> <!-- Use the latest version -->
</dependency>
</dependencies>

23
Q

Liquibase: Step 2: Create Database Configuration

A

Create a liquibase.properties file in your project’s src/main/resources directory with your database configuration:

url=jdbc:postgresql://your-database-host:5432/your-database
username=your-username
password=your-password

24
Q

Liquibase: Step 3: Write a Changelog

A

Create a Liquibase changelog file, e.g., changelog.xml, in the src/main/resources/db/changelog directory. Add your changesets to this file. For example:

<!-- db/changelog/changelog.xml -->

<databaseChangeLog>

<changeSet>
<createTable>
<column>
<constraints></constraints>
</column>
<column></column>
</createTable>
</changeSet>

</databaseChangeLog>

25
Q

Liquibase: Step 4: Java Application Entry Point

A

Create a class with a main method to serve as the entry point. In this example, we’ll create LiquibaseApp.java:

import liquibase.Liquibase;
import liquibase.database.Database;
import liquibase.database.DatabaseFactory;
import liquibase.database.jvm.JdbcConnection;
import liquibase.resource.ClassLoaderResourceAccessor;

import java.sql.Connection;
import java.sql.DriverManager;

public class LiquibaseApp {

public static void main(String[] args) throws Exception {
    // Open a database connection
    Connection connection = DriverManager.getConnection("jdbc:postgresql://your-database-host:5432/your-database",
            "your-username", "your-password");

    // Create a Liquibase instance
    Database database = DatabaseFactory.getInstance()
            .findCorrectDatabaseImplementation(new JdbcConnection(connection));
    Liquibase liquibase = new Liquibase("db/changelog/changelog.xml", new ClassLoaderResourceAccessor(), database);

    // Run the migration
    liquibase.update("");

    // Close the database connection
    connection.close();
} }
26
Q

Liquibase: Step 5: Run the Application

A

Run your Java application, and Liquibase will automatically apply the database changes defined in your changelog.

This is a basic example, and you can explore additional Liquibase features, such as handling different databases, managing contexts, and integrating with different build tools. Remember to replace the placeholder values (e.g., database URL, username, password) with your actual database configuration.