Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add back hsqldb #716

Merged
merged 9 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/docker-build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ jobs:
matrix:
docker-compose-file:
- docker-compose.yml
- testing/docker-compose.hsqldb.yml
- testing/docker-compose.cockroachdb.yml
- testing/docker-compose.yugabytedb.yml
dockerfile:
Expand Down
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ dependencies {
implementation 'io.activej:activej-boot:5.5'
implementation 'io.activej:activej-specializer:5.5'
implementation 'io.activej:activej-launchers-http:5.5'
implementation 'org.hsqldb:hsqldb:2.7.2'
implementation 'org.postgresql:postgresql:42.6.0'
implementation 'org.hibernate:hibernate-core:6.3.1.Final'
implementation 'org.hibernate:hibernate-hikaricp:6.3.1.Final'
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/me/kavin/piped/utils/LiquibaseHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public static void init() throws Exception {

// register YugabyteDB database
DatabaseFactory.getInstance().register(new liquibase.ext.yugabytedb.database.YugabyteDBDatabase());
// register HsqlDatabase database
DatabaseFactory.getInstance().register(new liquibase.database.core.HsqlDatabase());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this really necessary? We only add YugabyteDB since it's not included in the core liquibase.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch! I will try without


Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(new JdbcConnection(DriverManager.getConnection(url, username, password)));

Expand Down
1 change: 0 additions & 1 deletion src/main/resources/changelog/db.changelog-master.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@

<include file="version/0-init.xml" relativeToChangelogFile="true"/>
<include file="version/1-fix-subs.xml" relativeToChangelogFile="true"/>

</databaseChangeLog>
135 changes: 135 additions & 0 deletions src/main/resources/changelog/version/0-1-init-hsqldb.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
CREATE TABLE IF NOT EXISTS users (
id BIGSERIAL NOT NULL,
password TEXT NULL,
session_id VARCHAR(36) NULL,
username VARCHAR(24) NULL UNIQUE,
CONSTRAINT users_pkey PRIMARY KEY (id)
);

DROP INDEX users.users_id_idx IF EXISTS;

CREATE INDEX IF NOT EXISTS username_idx ON users (username ASC);

-- rollback DROP TABLE users IF EXISTS

CREATE TABLE IF NOT EXISTS channels (
uploader_id VARCHAR(24) NOT NULL,
uploader VARCHAR(100) NULL,
uploader_avatar VARCHAR(150) NULL,
verified BOOLEAN NULL,
CONSTRAINT channels_pkey PRIMARY KEY (uploader_id)
);

CREATE INDEX IF NOT EXISTS channels_uploader_idx ON channels (uploader ASC);

-- rollback DROP TABLE channels IF EXISTS

CREATE TABLE IF NOT EXISTS pubsub (
id VARCHAR(24) NOT NULL,
subbed_at INT8 NULL,
CONSTRAINT pubsub_pkey PRIMARY KEY (id)
);

CREATE INDEX IF NOT EXISTS pubsub_id_idx ON pubsub (id ASC);

-- rollback DROP TABLE pubsub IF EXISTS

CREATE TABLE IF NOT EXISTS playlists (
id BIGSERIAL NOT NULL,
name VARCHAR(200) NULL,
playlist_id UUID NOT NULL UNIQUE DEFAULT uuid(),
short_description VARCHAR(100) NULL,
thumbnail VARCHAR(300) NULL,
owner INT8 NOT NULL,
CONSTRAINT playlists_pkey PRIMARY KEY (id),
CONSTRAINT fk_playlists_owner FOREIGN KEY (owner) REFERENCES users(id)
);

-- rollback DROP TABLE playlists IF EXISTS

CREATE TABLE IF NOT EXISTS playlist_videos (
id VARCHAR(11) NOT NULL,
duration INT8 NULL,
thumbnail VARCHAR(400) NULL,
title VARCHAR(120) NULL,
uploader_id VARCHAR(24) NOT NULL,
CONSTRAINT playlist_videos_pkey PRIMARY KEY (id),
CONSTRAINT fk_playlist_video_uploader_id FOREIGN KEY (uploader_id) REFERENCES channels(uploader_id)
);

CREATE INDEX IF NOT EXISTS playlist_videos_id_idx ON playlist_videos (id ASC);
CREATE INDEX IF NOT EXISTS playlist_videos_uploader_id_idx ON playlist_videos (uploader_id ASC);

-- rollback DROP TABLE playlist_videos IF EXISTS

CREATE TABLE IF NOT EXISTS playlists_videos_ids (
playlist_id INT8 NOT NULL,
videos_id VARCHAR(11) NOT NULL,
videos_order INT4 NOT NULL,
CONSTRAINT playlists_videos_ids_pkey PRIMARY KEY (playlist_id, videos_order),
CONSTRAINT fk_playlists_videos_video_id_playlist_video FOREIGN KEY (videos_id) REFERENCES playlist_videos(id),
CONSTRAINT fk_playlists_videos_playlist_id_playlist FOREIGN KEY (playlist_id) REFERENCES playlists(id)
);

CREATE INDEX IF NOT EXISTS playlists_videos_ids_playlist_id_idx ON playlists_videos_ids (playlist_id ASC);

-- rollback DROP TABLE playlists_videos_ids IF EXISTS

CREATE TABLE IF NOT EXISTS unauthenticated_subscriptions (
id VARCHAR(24) NOT NULL,
subscribed_at INT8 NOT NULL,
CONSTRAINT unauthenticated_subscriptions_pkey PRIMARY KEY (id),
CONSTRAINT fk_unauthenticated_subscriptions_id_channels FOREIGN KEY (id) REFERENCES channels(uploader_id)
);

CREATE INDEX IF NOT EXISTS unauthenticated_subscriptions_subscribed_at_idx ON unauthenticated_subscriptions (subscribed_at ASC);

-- rollback DROP TABLE unauthenticated_subscriptions IF EXISTS

CREATE INDEX IF NOT EXISTS users_session_id_idx ON users (session_id ASC);

-- rollback DROP INDEX users_session_id_idx IF EXISTS

CREATE TABLE IF NOT EXISTS videos (
id VARCHAR(11) NOT NULL UNIQUE,
duration INT8 NULL,
thumbnail VARCHAR(400) NULL,
title VARCHAR(120) NULL,
uploaded INT8 NULL,
views INT8 NULL,
uploader_id VARCHAR(24) NOT NULL,
is_short BOOLEAN NOT NULL DEFAULT false,
CONSTRAINT videos_pkey PRIMARY KEY (id, uploader_id),
CONSTRAINT fk_videos_channels_uploader_id FOREIGN KEY (uploader_id) REFERENCES channels(uploader_id)
);

CREATE UNIQUE INDEX IF NOT EXISTS videos_id_idx ON videos (id ASC);
CREATE INDEX IF NOT EXISTS video_uploaded_idx ON videos (uploaded ASC);
CREATE INDEX IF NOT EXISTS video_uploader_id_idx ON videos (uploader_id ASC);

-- rollback DROP TABLE videos IF EXISTS

CREATE TABLE IF NOT EXISTS users_subscribed (
subscriber INT8 NOT NULL,
channel VARCHAR(24) NOT NULL,
CONSTRAINT users_subscribed_pkey PRIMARY KEY (subscriber, channel),
CONSTRAINT fk_subscriber_users FOREIGN KEY (subscriber) REFERENCES users(id)
);

CREATE INDEX IF NOT EXISTS users_subscribed_subscriber_idx ON users_subscribed (subscriber ASC);
CREATE INDEX IF NOT EXISTS users_subscribed_channel_idx ON users_subscribed (channel ASC);

-- rollback DROP TABLE users_subscribed IF EXISTS

CREATE INDEX IF NOT EXISTS pubsub_subbed_at_idx ON pubsub (subbed_at ASC);

-- rollback DROP INDEX pubsub_subbed_at_idx IF EXISTS

CREATE INDEX IF NOT EXISTS playlists_playlist_id_idx ON playlists (playlist_id ASC);
CREATE INDEX IF NOT EXISTS playlists_owner_idx ON playlists (owner ASC);

-- rollback DROP INDEX playlists_playlist_id_idx IF EXISTS
-- rollback DROP INDEX playlists_owner_idx IF EXISTS
CREATE INDEX IF NOT EXISTS unauthenticated_subscriptions_id_idx ON unauthenticated_subscriptions (id ASC);

-- rollback DROP INDEX unauthenticated_subscriptions_id_idx IF EXISTS
3 changes: 2 additions & 1 deletion src/main/resources/changelog/version/0-init.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
</changeSet>

<changeSet id="0-1" author="kavin" runInTransaction="false">
<sqlFile path="0-1-init.sql" relativeToChangelogFile="true"/>
<sqlFile path="0-1-init.sql" dbms="!hsqldb" relativeToChangelogFile="true"/>
<sqlFile path="0-1-init-crdb.sql" dbms="cockroachdb" relativeToChangelogFile="true"/>
<sqlFile path="0-1-init-pg.sql" dbms="postgresql,yugabytedb" relativeToChangelogFile="true"/>
<sqlFile path="0-1-init-hsqldb.sql" dbms="hsqldb" relativeToChangelogFile="true" stripComments="true"/>
</changeSet>

</databaseChangeLog>
15 changes: 14 additions & 1 deletion src/main/resources/changelog/version/1-fix-subs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,25 @@
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
https://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-latest.xsd">

<changeSet id="1-0" author="kavin" runInTransaction="false">
<changeSet id="1-0" author="kavin" dbms="!hsqldb" runInTransaction="false">
<!-- drop constraint since it prevents breaks unauthenticated subscriptions from working -->
<sql>ALTER TABLE unauthenticated_subscriptions DROP CONSTRAINT IF EXISTS fk_unauthenticated_subscriptions_id_channels;</sql>
<rollback>
<sql>ALTER TABLE unauthenticated_subscriptions ADD CONSTRAINT fk_unauthenticated_subscriptions_id_channels FOREIGN KEY (id) REFERENCES channels(uploader_id);</sql>
</rollback>
</changeSet>
<changeSet id="1-0-hsqldb" author="kavin" dbms="hsqldb" runInTransaction="false">
<!-- drop constraint since it prevents breaks unauthenticated subscriptions from working -->
<dropForeignKeyConstraint baseTableName="unauthenticated_subscriptions" constraintName="fk_unauthenticated_subscriptions_id_channels"/>
<rollback>
<dropForeignKeyConstraint baseTableName="unauthenticated_subscriptions" constraintName="fk_unauthenticated_subscriptions_id_channels"/>
<addForeignKeyConstraint baseColumnNames="id"
baseTableName="unauthenticated_subscriptions"
constraintName="fk_unauthenticated_subscriptions_id_channels"
referencedColumnNames="id"
referencedTableName="channels"
validate="true"/>
</rollback>
</changeSet>
FireMasterK marked this conversation as resolved.
Show resolved Hide resolved

</databaseChangeLog>
18 changes: 18 additions & 0 deletions testing/config.hsqldb.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# The port to Listen on.
PORT: 8080

# Proxy
PROXY_PART: https://pipedproxy-ams.kavin.rocks

# Public API URL
API_URL: https://pipedapi.kavin.rocks

# Public Frontend URL
FRONTEND_URL: https://piped.video

# Hibernate properties
hibernate.connection.url: jdbc:hsqldb:mem:memdb;sql.syntax_pgs=true
hibernate.connection.driver_class: org.hsqldb.jdbcDriver
hibernate.dialect: org.hibernate.dialect.HSQLDialect
hibernate.connection.username: piped
hibernate.connection.password: changeme
8 changes: 8 additions & 0 deletions testing/docker-compose.hsqldb.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
services:
piped:
image: 1337kavin/piped:latest
restart: unless-stopped
ports:
- "127.0.0.1:8080:8080"
volumes:
- ./config.hsqldb.properties:/app/config.properties
Loading