Merge pull request #226 from igalic/feat/sqlite

Add SQLite as supported database
This commit is contained in:
Baptiste Gelez 2018-10-06 12:15:00 +01:00 committed by GitHub
commit b464671cf0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
129 changed files with 598 additions and 265 deletions

3
.gitignore vendored
View File

@ -9,3 +9,6 @@ po/*.po~
Rocket.toml
media
docker-compose.yml
*.db
*.sqlite
*.sqlite3

View File

@ -1,4 +1,10 @@
language: rust
env:
matrix:
- MIGRATION_DIR=migrations/postgres FEATURES=postgres DATABASE_URL=postgres://postgres@localhost/plume
- MIGRATION_DIR=migrations/sqlite FEATURES=sqlite DATABASE_URL=plume.sqlite3
rust:
- nightly
cache: cargo
script:
- cargo build --no-default-features --features="${FEATURES}"

11
Cargo.lock generated
View File

@ -475,6 +475,7 @@ dependencies = [
"byteorder 1.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
"chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
"diesel_derives 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"libsqlite3-sys 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)",
"pq-sys 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
"r2d2 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
@ -1001,6 +1002,15 @@ dependencies = [
"crc 1.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "libsqlite3-sys"
version = "0.9.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"pkg-config 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)",
"vcpkg 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "locale_config"
version = "0.2.2"
@ -2882,6 +2892,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum lazycell 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d33a48d0365c96081958cc663eef834975cb1e8d8bea3378513fc72bdbf11e50"
"checksum libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)" = "76e3a3ef172f1a0b9a9ff0dd1491ae5e6c948b94479a3021819ba7d860c8645d"
"checksum libflate 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "7d4b4c7aff5bac19b956f693d0ea0eade8066deb092186ae954fa6ba14daab98"
"checksum libsqlite3-sys 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)" = "d3711dfd91a1081d2458ad2d06ea30a8755256e74038be2ad927d94e1c955ca8"
"checksum locale_config 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "14fbee0e39bc2dd6a2427c4fdea66e9826cc1fd09b0a0b7550359f5f6efe1dab"
"checksum lock_api 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "949826a5ccf18c1b3a7c3d57692778d21768b79e46eb9dd07bfc4c2160036c54"
"checksum log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "e19e8d5c34a3e0e2223db8e060f9e8264aeeb5c5fc64a4ee9965c062211c024b"

View File

@ -29,7 +29,7 @@ features = ["serde"]
version = "0.4"
[dependencies.diesel]
features = ["postgres", "r2d2", "chrono"]
features = ["postgres", "sqlite", "r2d2", "chrono"]
version = "*"
[dependencies.plume-api]
@ -62,5 +62,10 @@ rev = "2805ce5dbae4a6441208484426440885a5640a6a"
git = "https://github.com/BaptisteGelez/rocket_i18n"
rev = "75a3bfd7b847324c078a355a7f101f8241a9f59b"
[features]
default = ["postgres"]
postgres = ["plume-models/postgres"]
sqlite = ["plume-models/sqlite"]
[workspace]
members = ["plume-api", "plume-models", "plume-common"]

5
diesel.toml Normal file
View File

@ -0,0 +1,5 @@
# For documentation on how to configure this file,
# see diesel.rs/guides/configuring-diesel-cli
[print_schema]
file = "plume-models/src/schema.rs"

View File

@ -0,0 +1,2 @@
-- This file should undo anything in `up.sql`
DROP TABLE instances;

View File

@ -0,0 +1,15 @@
-- Your SQL goes here
CREATE TABLE instances (
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
public_domain VARCHAR NOT NULL,
name VARCHAR NOT NULL,
local BOOLEAN NOT NULL DEFAULT 'f',
blocked BOOLEAN NOT NULL DEFAULT 'f',
creation_date DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
open_registrations BOOLEAN NOT NULL DEFAULT 't',
short_description TEXT NOT NULL DEFAULT '',
long_description TEXT NOT NULL DEFAULT '',
default_license TEXT NOT NULL DEFAULT 'CC-0',
long_description_html VARCHAR NOT NULL DEFAULT '',
short_description_html VARCHAR NOT NULL DEFAULT ''
)

View File

@ -0,0 +1,2 @@
-- This file should undo anything in `up.sql`
DROP TABLE users;

View File

@ -0,0 +1,23 @@
-- Your SQL goes here
PRAGMA foreign_keys = ON;
CREATE TABLE users (
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
username VARCHAR NOT NULL,
display_name VARCHAR NOT NULL DEFAULT '',
outbox_url VARCHAR NOT NULL,
inbox_url VARCHAR NOT NULL,
is_admin BOOLEAN NOT NULL DEFAULT 'f',
summary TEXT NOT NULL DEFAULT '',
email TEXT,
hashed_password TEXT,
instance_id INTEGER REFERENCES instances(id) ON DELETE CASCADE NOT NULL,
creation_date DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
ap_url TEXT NOT NULL default '',
private_key TEXT,
public_key TEXT NOT NULL DEFAULT '',
shared_inbox_url VARCHAR,
followers_endpoint VARCHAR NOT NULL DEFAULT '',
avatar_id INTEGER REFERENCES medias(id) ON DELETE CASCADE,
last_fetched_date TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (avatar_id) REFERENCES medias(id) ON DELETE SET NULL
);

View File

@ -0,0 +1,2 @@
-- This file should undo anything in `up.sql`
DROP TABLE blogs;

View File

@ -0,0 +1,14 @@
-- Your SQL goes here
CREATE TABLE blogs (
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
actor_id VARCHAR NOT NULL,
title VARCHAR NOT NULL,
summary TEXT NOT NULL DEFAULT '',
outbox_url VARCHAR NOT NULL,
inbox_url VARCHAR NOT NULL,
instance_id INTEGER REFERENCES instances(id) ON DELETE CASCADE NOT NULL,
creation_date DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
ap_url text not null default '',
private_key TEXT,
public_key TEXT NOT NULL DEFAULT ''
)

View File

@ -0,0 +1,2 @@
-- This file should undo anything in `up.sql`
DROP TABLE blog_authors;

View File

@ -0,0 +1,7 @@
-- Your SQL goes here
CREATE TABLE blog_authors (
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
blog_id INTEGER REFERENCES blogs(id) ON DELETE CASCADE NOT NULL,
author_id INTEGER REFERENCES users(id) ON DELETE CASCADE NOT NULL,
is_owner BOOLEAN NOT NULL DEFAULT 'f'
)

View File

@ -0,0 +1,2 @@
-- This file should undo anything in `up.sql`
DROP TABLE posts;

View File

@ -0,0 +1,14 @@
-- Your SQL goes here
CREATE TABLE posts (
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
blog_id INTEGER REFERENCES blogs(id) ON DELETE CASCADE NOT NULL,
slug VARCHAR NOT NULL,
title VARCHAR NOT NULL,
content TEXT NOT NULL DEFAULT '',
published BOOLEAN NOT NULL DEFAULT 'f',
license VARCHAR NOT NULL DEFAULT 'CC-0',
creation_date DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
ap_url VARCHAR NOT NULL DEFAULT '',
subtitle TEXT NOT NULL DEFAULT '',
source TEXT NOT NULL DEFAULT ''
)

View File

@ -0,0 +1,2 @@
-- This file should undo anything in `up.sql`
DROP TABLE post_authors;

View File

@ -0,0 +1,6 @@
-- Your SQL goes here
CREATE TABLE post_authors (
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
post_id INTEGER REFERENCES posts(id) ON DELETE CASCADE NOT NULL,
author_id INTEGER REFERENCES users(id) ON DELETE CASCADE NOT NULL
)

View File

@ -0,0 +1,2 @@
-- This file should undo anything in `up.sql`
DROP TABLE follows;

View File

@ -0,0 +1,7 @@
-- Your SQL goes here
CREATE TABLE follows (
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
follower_id INTEGER REFERENCES users(id) ON DELETE CASCADE NOT NULL,
following_id INTEGER REFERENCES users(id) ON DELETE CASCADE NOT NULL,
ap_url TEXT NOT NULL default ''
)

View File

@ -0,0 +1,2 @@
-- This file should undo anything in `up.sql`
DROP TABLE comments;

View File

@ -0,0 +1,12 @@
-- Your SQL goes here
CREATE TABLE comments (
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
content TEXT NOT NULL DEFAULT '',
in_response_to_id INTEGER REFERENCES comments(id),
post_id INTEGER REFERENCES posts(id) ON DELETE CASCADE NOT NULL,
author_id INTEGER REFERENCES users(id) ON DELETE CASCADE NOT NULL,
creation_date DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
ap_url VARCHAR,
sensitive BOOLEAN NOT NULL DEFAULT 'f',
spoiler_text TEXT NOT NULL DEFAULT ''
)

View File

@ -0,0 +1,2 @@
-- This file should undo anything in `up.sql`
DROP TABLE likes;

View File

@ -0,0 +1,8 @@
-- Your SQL goes here
CREATE TABLE likes (
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
user_id INTEGER REFERENCES users(id) ON DELETE CASCADE NOT NULL,
post_id INTEGER REFERENCES posts(id) ON DELETE CASCADE NOT NULL,
creation_date DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
ap_url VARCHAR NOT NULL default ''
)

View File

@ -0,0 +1,2 @@
-- This file should undo anything in `up.sql`
DROP TABLE notifications;

View File

@ -0,0 +1,8 @@
-- Your SQL goes here
CREATE TABLE notifications (
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
user_id INTEGER REFERENCES users(id) ON DELETE CASCADE NOT NULL,
creation_date DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
kind VARCHAR NOT NULL DEFAULT 'unknown',
object_id INTEGER NOT NULL DEFAULT 0
)

View File

@ -0,0 +1,2 @@
-- This file should undo anything in `up.sql`
DROP TABLE reshares;

Some files were not shown because too many files have changed in this diff Show More