mirror of
https://github.com/Lumither/nocturne.git
synced 2026-10-17 10:26:21 +00:00
feat(migration) add migration
This commit is contained in:
9 files changed
+84
-22
No files matched your search
+14
-13
@@ -1,16 +1,17 @@
|
||||
use chrono::Utc;
|
||||
use git2::Repository;
|
||||
// use chrono::Utc;
|
||||
// use git2::Repository;
|
||||
|
||||
fn main() {
|
||||
let repo = Repository::open("../..").expect("failed to open repository");
|
||||
let commit = repo
|
||||
.head()
|
||||
.expect("failed to get HEAD")
|
||||
.peel_to_commit()
|
||||
.expect("failed to get HEAD commit");
|
||||
let hash = commit.id().to_string();
|
||||
let utc_timestamp = Utc::now().date_naive().format("%Y%m%d").to_string();
|
||||
let pkg_version = env!("CARGO_PKG_VERSION");
|
||||
let build_id = format!("{}:{}@{}", pkg_version, &hash[..8], utc_timestamp);
|
||||
println!("cargo:rustc-env=BUILD_ID={}", build_id);
|
||||
// let repo = Repository::open("../..").expect("failed to open repository");
|
||||
// let commit = repo
|
||||
// .head()
|
||||
// .expect("failed to get HEAD")
|
||||
// .peel_to_commit()
|
||||
// .expect("failed to get HEAD commit");
|
||||
// let hash = commit.id().to_string();
|
||||
// let utc_timestamp = Utc::now().date_naive().format("%Y%m%d").to_string();
|
||||
// let pkg_version = env!("CARGO_PKG_VERSION");
|
||||
// let build_id = format!("{}:{}@{}", pkg_version, &hash[..8], utc_timestamp);
|
||||
// println!("cargo:rustc-env=BUILD_ID={}", build_id);
|
||||
println!("cargo:rustc-env=BUILD_ID=undefined");
|
||||
}
|
||||
@@ -1,66 +0,0 @@
|
||||
CREATE TABLE tags
|
||||
(
|
||||
id SERIAL PRIMARY KEY,
|
||||
name VARCHAR(20) UNIQUE NOT NULL,
|
||||
description TEXT DEFAULT ''
|
||||
);
|
||||
|
||||
CREATE TABLE categories
|
||||
(
|
||||
id SERIAL PRIMARY KEY,
|
||||
name VARCHAR(20) UNIQUE NOT NULL,
|
||||
description TEXT DEFAULT ''
|
||||
);
|
||||
|
||||
CREATE TABLE post_status
|
||||
(
|
||||
name VARCHAR(20) PRIMARY KEY
|
||||
);
|
||||
|
||||
INSERT INTO post_status (name)
|
||||
VALUES ('draft'),
|
||||
('published'),
|
||||
('planned'),
|
||||
('hidden');
|
||||
|
||||
CREATE TABLE posts
|
||||
(
|
||||
id UUID PRIMARY KEY,
|
||||
identifier VARCHAR(100) UNIQUE NOT NULL,
|
||||
title VARCHAR(255) NOT NULL,
|
||||
subtitle VARCHAR(255) NOT NULL,
|
||||
date_created DATE NOT NULL,
|
||||
date_updated DATE,
|
||||
status VARCHAR(20) REFERENCES post_status (name) NOT NULL,
|
||||
content TEXT NOT NULL,
|
||||
hash VARCHAR(44) NOT NULL,
|
||||
category INTEGER REFERENCES categories (id) NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE post_tag
|
||||
(
|
||||
post UUID REFERENCES posts (id) ON DELETE CASCADE,
|
||||
tag INTEGER REFERENCES tags (id) ON DELETE CASCADE,
|
||||
|
||||
CONSTRAINT post_tag_pk PRIMARY KEY (post, tag)
|
||||
);
|
||||
|
||||
CREATE TABLE metadata
|
||||
(
|
||||
pid UUID REFERENCES posts (id) ON DELETE CASCADE NOT NULL,
|
||||
meta_key VARCHAR(50) NOT NULL,
|
||||
meta_value TEXT NOT NULL,
|
||||
|
||||
CONSTRAINT metadata_pk PRIMARY KEY (pid, meta_key)
|
||||
);
|
||||
|
||||
-- index
|
||||
CREATE INDEX idx_tags_name ON tags (name);
|
||||
CREATE INDEX idx_categories_name ON categories (name);
|
||||
CREATE INDEX idx_posts_identifier ON posts (identifier);
|
||||
CREATE INDEX idx_posts_status ON posts (status);
|
||||
CREATE INDEX idx_posts_category ON posts (category);
|
||||
CREATE INDEX idx_posts_date_created ON posts (date_created);
|
||||
CREATE INDEX idx_post_tag_post ON post_tag (post);
|
||||
CREATE INDEX idx_post_tag_tag ON post_tag (tag);
|
||||
CREATE INDEX idx_metadata_pid ON metadata (pid);
|
||||
Reference in new issue
Block a user