Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Add assertions for database structure

Open
#12 6 comments 0 reactions 1 assignee View on GitHub

@regis1512 is already working on this.

Since Jul 9, 2015.

Assessment

This issue has not been assessed yet.

Description

enhancement

I need assertions for checking database structure.
E.g. I want to check if specific table exists in database.

Proposed assertions:
assertThat(table).exists();
or
assertThat(source).tableExists("name");

Additionally it would be nice to have convinience method isEmpty() for
assertThat(table).hasNumberOfRows(0);

JDBC code to check if table exists ()

public static boolean hasTable(DataSource ds, String name) {
        boolean exists = false;

        try(Connection c = ds.getConnection();
            //table names usually stored in database uppercased
            ResultSet rs = c.getMetaData().getTables(null, null, name.toUpperCase(), null)) {

            if (rs.next()) {
                exists = true; // table exists
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        return exists;
    }

Or just do some operation and catch jdbc exception: table not exists. Below assertion partially does the trick, but is not elegant.
assertThat(table).hasNumberOfRows(0);

Dominant language
Java
Stars
130
Forks
21
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from assertj/assertj-db

All issues in assertj/assertj-db

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.