package com.eactive.kakao.rolling.impl;

import java.util.EnumSet;

import org.hibernate.boot.MetadataSources;
import org.hibernate.boot.registry.StandardServiceRegistry;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.tool.hbm2ddl.SchemaExport;
import org.hibernate.tool.schema.TargetType;

import com.eactive.kakao.rolling.CurrentCommitId;
import com.eactive.kakao.rolling.RollingSuffix;

public class SchemaGenerator {

	public static void main(String[] args) {
		StandardServiceRegistry registry = new StandardServiceRegistryBuilder()
//				.applySetting("hibernate.dialect", "org.hibernate.dialect.Oracle10gDialect")
				.applySetting("hibernate.dialect", "org.hibernate.dialect.PostgreSQL10Dialect")
				.build();

		MetadataSources metadata = new MetadataSources(registry);

		// 엔티티 클래스 추가
		metadata.addAnnotatedClass(RollingSuffix.class);
		// rolling_suffix
		metadata.addAnnotatedClass(CurrentCommitId.class);

		SchemaExport export = new SchemaExport();
		export.setFormat(true);
		export.setOutputFile("build/create.sql");
		export.createOnly(EnumSet.of(TargetType.SCRIPT), metadata.buildMetadata());

		StandardServiceRegistryBuilder.destroy(registry);
	}
}
