
--------------------------------------------------------------------------------

-- This migration script adds the ceres database and user and sets
-- permissions.

-- Run this migration via `sudo mariadb -u root < 0001_migration.sql`. Mind
-- that you also have to create the ceres Linux user. This is possibly done
-- by the systemd *.sysusers file.

-- create database for ceres, add ceres user and set privileges
CREATE DATABASE IF NOT EXISTS ceres;
CREATE USER IF NOT EXISTS 'ceres'@'localhost' IDENTIFIED VIA unix_socket;
GRANT ALL PRIVILEGES on ceres.* to 'ceres'@'localhost';
FLUSH PRIVILEGES;

-- select correct database for the rest of this script
USE ceres;

-- create meta table and set database schema version
CREATE TABLE IF NOT EXISTS meta (
	identifier varchar(80) PRIMARY KEY NOT NULL UNIQUE,
	value varchar(80) NOT NULL
);
INSERT INTO meta (identifier,value) VALUES ('version', '1');
