001package io.ebeaninternal.dbmigration.ddlgeneration.platform; 002 003import io.ebean.config.DatabaseConfig; 004import io.ebeaninternal.dbmigration.ddlgeneration.DdlBuffer; 005import io.ebeaninternal.dbmigration.ddlgeneration.DdlWrite; 006import io.ebeaninternal.dbmigration.migration.AddHistoryTable; 007import io.ebeaninternal.dbmigration.migration.DropHistoryTable; 008import io.ebeaninternal.dbmigration.model.MTable; 009 010import java.io.IOException; 011 012/** 013 * History DDL for MariaDB. 014 */ 015public class MariaDbHistoryDdl implements PlatformHistoryDdl { 016 017 @Override 018 public void configure(DatabaseConfig config, PlatformDdl platformDdl) { 019 // do nothing 020 } 021 022 @Override 023 public void createWithHistory(DdlWrite writer, MTable table) throws IOException { 024 String baseTable = table.getName(); 025 enableSystemVersioning(writer, baseTable); 026 } 027 028 private void enableSystemVersioning(DdlWrite writer, String baseTable) throws IOException { 029 DdlBuffer apply = writer.applyHistoryView(); 030 apply.append("alter table ").append(baseTable).append(" add system versioning").endOfStatement(); 031 032 DdlBuffer drop = writer.dropAll(); 033 drop.append("alter table ").append(baseTable).append(" drop system versioning").endOfStatement(); 034 } 035 036 @Override 037 public void dropHistoryTable(DdlWrite writer, DropHistoryTable dropHistoryTable) throws IOException { 038 String baseTable = dropHistoryTable.getBaseTable(); 039 DdlBuffer apply = writer.applyHistoryView(); 040 apply.append("alter table ").append(baseTable).append(" drop system versioning").endOfStatement(); 041 } 042 043 @Override 044 public void addHistoryTable(DdlWrite writer, AddHistoryTable addHistoryTable) throws IOException { 045 String baseTable = addHistoryTable.getBaseTable(); 046 enableSystemVersioning(writer, baseTable); 047 } 048 049 @Override 050 public void updateTriggers(DdlWrite writer, HistoryTableUpdate baseTable) { 051 // do nothing 052 } 053}