CREATE TABLE IF NOT EXISTS [ServerSettings] (
	[SettingID] INTEGER PRIMARY KEY,
	[Name] TEXT NOT NULL,
	[Description] TEXT NOT NULL,
	[Value] TEXT NOT NULL
);

CREATE TABLE IF NOT EXISTS [Users] (
	[UserID] INTEGER PRIMARY KEY,
	[Name] TEXT NOT NULL,
	[Email] TEXT,
	[AuthType] TEXT NOT NULL,
	[Salt] TEXT,
	[HashedPWSalt] TEXT
);

CREATE TABLE IF NOT EXISTS [Items] (
	[ItemID] INTEGER PRIMARY KEY,
	[UserID] INTEGER NOT NULL,
	[EXIFDate] TEXT NOT NULL,
	[UploadDate] TEXT NOT NULL,
	[Latitude] TEXT,
	[Longitude] TEXT,
	[Type] INTEGER, /* 0 = Photo, 1 = Video */
	[RelPath] TEXT NOT NULL,
    FOREIGN KEY (UserID) REFERENCES Users(UserID)
);

CREATE TABLE IF NOT EXISTS [Tags] (
	[TagID] INTEGER PRIMARY KEY,
    [TagName] TEXT NOT NULL
);

CREATE TABLE IF NOT EXISTS [ItemTags] (
	[ItemID] INTEGER NOT NULL,
	[TagID] INTEGER NOT NULL,
    FOREIGN KEY (ItemID) REFERENCES Items(ItemID)
    FOREIGN KEY (TagID) REFERENCES Tags(TagID)
);

CREATE TABLE IF NOT EXISTS [Albums] (
	[AlbumID] INTEGER PRIMARY KEY,
    [UserID] INTEGER NOT NULL,
    [Name] TEXT NOT NULL,
    FOREIGN KEY (UserID) REFERENCES Users(UserID)
);

CREATE TABLE IF NOT EXISTS [ItemAlbums] (
	[ItemID] INTEGER NOT NULL,
	[AlbumID] INTEGER NOT NULL,
    FOREIGN KEY (ItemID) REFERENCES Items(ItemID)
    FOREIGN KEY (AlbumID) REFERENCES Albums(AlbumID)
);
