
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;

public class Modelo {
	private Connection connection;
	private static final String crearDB = "create database if not exists gestionGastos;\n";
	private static final String crearMes = "create table if not exists mes (\n" + 
			"	id int primary key,\n" + 
			"    anio int,\n" + 
			"    mes int,\n" + 
			"    total float\n" + 
			");\n";
	private static final String crearGestion = "create table if not exists gestion (\n" + 
			"	id int primary key,\n" + 
			"    id_mes int,\n" + 
			"    suma float,\n" + 
			"    foreign key (id_mes) references mes(id)\n" + 
			");\n";
	private static final String crearTranasccion = "create table if not exists transacciones (\n" + 
			"	id int primary key,\n" + 
			"    id_gestion int,\n" + 
			"    dinero float,\n" + 
			"    fecha date\n" + 
			");";
	
	Modelo(){
		try {
			connection = DriverManager.getConnection("jdbc:mariadb://localhost:3306/gestionGastos?user=root&password=1234");
			Statement crearDB = connection.createStatement();
			//crearDB.executeQuery(Modelo.scriptInicial);
			crearDB.executeQuery(Modelo.crearDB);
			crearDB.executeUpdate(Modelo.crearMes);
			crearDB.executeUpdate(Modelo.crearGestion);
			crearDB.executeUpdate(Modelo.crearTranasccion);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
}
