CREATE TABLE `maps` (
    `id_map` int(10) UNSIGNED auto_increment,
    `codename` VARCHAR(100),
    `geo_name` VARCHAR(100),
    `min_zoom` TINYINT UNSIGNED,
    `max_zoom` TINYINT UNSIGNED,
    `attribution` VARCHAR(100),
    `led` TIMESTAMP NOT NULL ON UPDATE CURRENT_TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id_map`));

CREATE TABLE `mappings` (
    `id_mapping` int(10) UNSIGNED auto_increment,
    `id_map` int(10) UNSIGNED,
    `id_project` int(10) UNSIGNED,
    `led` TIMESTAMP NOT NULL ON UPDATE CURRENT_TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id_mapping`));

ALTER TABLE mappings ADD INDEX(`id_map`);
ALTER TABLE mappings ADD FOREIGN KEY (`id_map`) REFERENCES maps(`id_map`);
ALTER TABLE mappings ADD INDEX(`id_project`);
ALTER TABLE mappings ADD FOREIGN KEY (`id_project`) REFERENCES projects(`id_project`);

INSERT INTO maps(codename, geo_name, min_zoom, max_zoom, attribution) VALUES
/*1*/('satellite', 'mapbox.satellite-streets', 0, 19, ''),
/*2*/('otm', 'opentopomap', 2, 19, ''),
/*3*/('ign_france', 'ign.fr', 2, 19, ''),
/*4*/('ign_spain', 'ign.es', 1, 20, ''),
/*5*/('linz', 'linz', 0, 17, 'Sourced from LINZ. CC BY 4.0'),
/*6*/('usgs', 'usgs', 1, 16, ''),
/*7*/('natgeo', 'natgeo.pct', 5, 14, '');

INSERT INTO mappings(id_map, id_project) VALUES
    (1, NULL),
    (2, NULL),
    (3, 2),
    (4, 2),
    (5, 1),
    (6, 3);
