Class TableSchema

java.lang.Object
group.worldstandard.pudel.api.database.TableSchema

public final class TableSchema extends Object
Schema definition for a plugin database table.

All tables automatically include an 'id' column (BIGSERIAL PRIMARY KEY) and 'created_at', 'updated_at' timestamp columns.

Example (manual column definition):


TableSchema schema = TableSchema.builder("user_settings")
    .column("user_id", ColumnType.BIGINT, false)
    .column("setting_name", ColumnType.STRING, 100, false)
    .column("setting_value", ColumnType.TEXT, true)
    .column("enabled", ColumnType.BOOLEAN, false, "true")
    .index("user_id")
    .uniqueIndex("user_id", "setting_name")
    .build();

Example (auto-generate from entity):


@Entity
public class UserSetting {
    private Long id;
    private Long userId;
    private String settingName;
    private String settingValue;

    @Column(nullable = false)
    private Boolean enabled = true;

    @Column(defaultValue = "true")
    private Boolean active;

    @Column(unique = true)
    private String email;

    @Column(index = true)
    private String username;

    private Instant createdAt;
    private Instant updatedAt;
    // getters and setters...
}

TableSchema schema = TableSchema.builder("user_settings")
    .fromEntity(UserSetting.class)
    .build(); // indexes from @Column(unique/index) are added automatically

  • Method Details

    • getTableName

      public String getTableName()
      Returns the name of the database table associated with this schema.
      Returns:
      the table name
    • getColumns

      public List<TableSchema.ColumnDefinition> getColumns()
      Returns the list of column definitions associated with this table schema.
      Returns:
      a list of TableSchema.ColumnDefinition objects representing the columns of the table
    • getIndexes

      public List<TableSchema.IndexDefinition> getIndexes()
      Returns the list of index definitions associated with this table schema.
      Returns:
      a list of TableSchema.IndexDefinition objects representing the indexes of the table
    • builder

      public static TableSchema.Builder builder(String tableName)
      Create a new schema builder.
      Parameters:
      tableName - the table name (will be prefixed automatically)
      Returns:
      a new builder