While there is an option to release a custom plugin to resolve issues specific to Postgres, I believe it would be more likely to be used if it was included in the main body.
Currently, it requires the following steps:
1. Automatically generate config.xml
2. Delete from the automatically generated file
So I think a plugin would be a better solution.
I have created the following.
If there are no problems, please consider introducing it in the next version.
https://github.com/mybatis/generator/issues/1353# Description
Adds SkipPartitionedWithPostgresTablesPlugin, a MyBatis Generator (MBG) plugin that skips generating artifacts (model classes, mappers, dynamic SQL support) for PostgreSQL partition child tables. It discovers all non-partition-child tables plus views (excluding pg_catalog and information_schema) and only generates code for those. Optionally writes the allowlist to a file. Supports case-insensitive matching.
# Background
PostgreSQL declarative partitioning creates a physical table for every partition. Generating MyBatis artifacts for each child partition leads to:
- A large number of nearly identical classes/mappers
- Churn when time-based partitions rotate
- Redundant code when logic works at the parent level or routing is external
This plugin:
- Queries PostgreSQL system catalogs (pg_inherits, pg_class, pg_tables, pg_views)
- Excludes partition child tables
- Keeps normal tables, partition parent tables, and views
- Fails fast (throws RuntimeException) if discovery or writing the allowlist fails
# Usage
Add the plugin inside an MBG <context> that has a PostgreSQL connection (either jdbcConnection or connectionFactory).
- Available properties:
- allowlistFile (optional): file path to write the discovered (sorted) table/view names
- caseInsensitive (optional, default false): perform case-insensitive matching
Example:
```xml
<context id="PostgresContext" targetRuntime="MyBatis3">
<jdbcConnection driverClass="org.postgresql.Driver"
connectionURL="jdbc:postgresql://localhost:5432/appdb"
userId="app"
password="secret"/>
<plugin type="org.mybatis.generator.plugins.SkipPartitionedWithPostgresTablesPlugin">
<property name="allowlistFile" value="build/mbg/allowlist.txt"/>
<property name="caseInsensitive" value="true"/>
</plugin>
<!-- Optional <table> elements. If omitted, MBG introspects all; the plugin filters afterward. -->
</context>
```
# Behavior summary:
- Discovers non-partition-child tables (excludes system schemas)
- Adds views (non-system schemas)
- Builds in-memory allowlist (+ optional file write) -
- Skips generation for anything not in the allowlist
- Runtime exception on any discovery or write failure
# Limitations / Notes:
- Partition parent tables are still included
- No custom schema include/exclude yet (only system schemas excluded)