<?xml version="1.0" encoding="UTF-8" ?>

<!DOCTYPE sqlMap PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN" 
"http://ibatis.apache.org/dtd/sql-map-2.dtd">

<sqlMap namespace="CreateTables">

<!-- .\ ARTIFACT \.________________________________________________________________________________________ -->

<statement id="createArtifactKeys">
  CREATE TABLE ArtifactKeys (
    GROUP_ID      varchar (100) not null,
    ARTIFACT_ID   varchar (100) not null,
    VERSION       varchar (50)  not null,
    CLASSIFIER    varchar (50),
    TYPE          varchar (20),
  	ARTIFACT_KEY  integer generated always as identity ( start with 1 ),
  	primary key ( GROUP_ID, ARTIFACT_ID, VERSION, CLASSIFIER, TYPE )
  )
</statement>

<statement id="dropArtifactKeys">
  DROP TABLE ArtifactKeys
</statement>


<!-- .\ METADATA \.________________________________________________________________________________________ -->

<!-- 
METADATA_KEYS is the index table for all other tables

need to make the lookup on this table fast, perhaps by indexing the combination of g:a:v in a lookup column

TODO: Ensure that there is never a duplicate of the multi-part complex key (groupId, artifactId, version)
 -->
<statement id="createMetadataKeys">
    CREATE TABLE MetadataKeys (
      metadataKey     integer generated always as identity ( start with 1 ) primary key,
      groupId         varchar(100) not null,
      artifactId      varchar(100) not null,
      version         varchar(100) not null
    )
</statement>

<statement id="dropMetadataKeys">
	DROP TABLE MetadataKeys
</statement>

<statement id="createRepositoryMetadata">
    CREATE TABLE RepositoryMetadata (
      metadataKey         integer not null,
      id                  integer generated always as identity ( start with 1 ) primary key,
      latest              varchar(100) not null,
      release             varchar(100) not null,
      lastUpdated         integer,
      snapshotTimestamp   integer,
      snapshotBuildNumber integer,
      snapshotLocalCopy   char(1),
      foreign key( metadataKey ) references MetadataKeys( metadataKey )
    )
</statement>

<statement id="dropRepositoryMetadata">
	DROP TABLE RepositoryMetadata
</statement>

<statement id="createHealthMetadata">
    CREATE TABLE HealthMetadata (
      metadataKey         integer not null,
      id                  integer generated always as identity ( start with 1 ) primary key,     
      processId           varchar(100) not null,
      problemId           varchar(100) not null,
      message             varchar(8000) not null,
      foreign key( metadataKey ) references MetadataKeys( metadataKey )
    )
</statement>

<statement id="createVersionsMetadata">
    CREATE TABLE VersionMetadata (
      metadataKey         integer not null,
      id             integer generated always as identity ( start with 1 ) primary key,
      version        varchar(100) not null,
      foreign key( metadataKey ) references MetadataKeys( metadataKey )
    )
</statement>

</sqlMap>