Compare commits
27 Commits
16275e5a95
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 9734ccb9a2 | |||
| d6605d803a | |||
| 6fdc2be4fc | |||
| 7aba08ef32 | |||
| 326b0e9947 | |||
| d835b5b76c | |||
| eb750432fe | |||
| 9225b8947d | |||
| c60ebb0bc7 | |||
| 2ef08463c9 | |||
| 79e0b7be27 | |||
| 8c5b36c282 | |||
| 24d8c7f08f | |||
| 32bab1844e | |||
| b8c7f8db1a | |||
| a617cceed1 | |||
| 689139a9e6 | |||
| 777ea50b62 | |||
| 4efee19a9d | |||
| fc9c73a20d | |||
| 51798e5e37 | |||
| daf8e99c86 | |||
| da3ba338b8 | |||
| bb9c5af87c | |||
| db383445ff | |||
| 191baaa204 | |||
| 9683d28d68 |
34
.gitea/workflows/release.yml
Normal file
34
.gitea/workflows/release.yml
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
name: Build and Push Docker Image
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [main]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build-and-push:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Check out repository code
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Log in to Docker Hub - Main web app container registry
|
||||||
|
uses: docker/login-action@v1
|
||||||
|
with:
|
||||||
|
registry: gitea.dropgaze.xyz
|
||||||
|
username: ${{ secrets.DOCKER_USERNAME }}
|
||||||
|
password: ${{ secrets.DOCKER_PASSWORD }}
|
||||||
|
|
||||||
|
- name: Set up QEMU
|
||||||
|
uses: docker/setup-qemu-action@v3
|
||||||
|
- name: Set up Docker Buildx
|
||||||
|
uses: docker/setup-buildx-action@v3
|
||||||
|
- name: Build and push
|
||||||
|
uses: docker/build-push-action@v6
|
||||||
|
with:
|
||||||
|
context: .
|
||||||
|
push: true
|
||||||
|
tags: gitea.dropgaze.xyz/jake/sprout-db-migrations:latest
|
||||||
|
platforms: |
|
||||||
|
linux/arm64
|
||||||
|
linux/amd64
|
||||||
5
Dockerfile
Normal file
5
Dockerfile
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
FROM amacneil/dbmate:latest
|
||||||
|
|
||||||
|
COPY ./db /db
|
||||||
|
|
||||||
|
CMD ["--wait", "up"]
|
||||||
85
db/migrations/20241024151641_pgulid.sql
Normal file
85
db/migrations/20241024151641_pgulid.sql
Normal file
@@ -0,0 +1,85 @@
|
|||||||
|
-- migrate:up
|
||||||
|
|
||||||
|
-- pgulid is based on OK Log's Go implementation of the ULID spec
|
||||||
|
--
|
||||||
|
-- https://github.com/oklog/ulid
|
||||||
|
-- https://github.com/ulid/spec
|
||||||
|
--
|
||||||
|
-- Copyright 2016 The Oklog Authors
|
||||||
|
-- Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
-- you may not use this file except in compliance with the License.
|
||||||
|
-- You may obtain a copy of the License at
|
||||||
|
--
|
||||||
|
-- http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
--
|
||||||
|
-- Unless required by applicable law or agreed to in writing, software
|
||||||
|
-- distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
-- See the License for the specific language governing permissions and
|
||||||
|
-- limitations under the License.
|
||||||
|
|
||||||
|
CREATE EXTENSION IF NOT EXISTS pgcrypto;
|
||||||
|
|
||||||
|
CREATE FUNCTION generate_ulid()
|
||||||
|
RETURNS TEXT
|
||||||
|
AS $$
|
||||||
|
DECLARE
|
||||||
|
-- Crockford's Base32
|
||||||
|
encoding BYTEA = '0123456789ABCDEFGHJKMNPQRSTVWXYZ';
|
||||||
|
timestamp BYTEA = E'\\000\\000\\000\\000\\000\\000';
|
||||||
|
output TEXT = '';
|
||||||
|
|
||||||
|
unix_time BIGINT;
|
||||||
|
ulid BYTEA;
|
||||||
|
BEGIN
|
||||||
|
-- 6 timestamp bytes
|
||||||
|
unix_time = (EXTRACT(EPOCH FROM CLOCK_TIMESTAMP()) * 1000)::BIGINT;
|
||||||
|
timestamp = SET_BYTE(timestamp, 0, (unix_time >> 40)::BIT(8)::INTEGER);
|
||||||
|
timestamp = SET_BYTE(timestamp, 1, (unix_time >> 32)::BIT(8)::INTEGER);
|
||||||
|
timestamp = SET_BYTE(timestamp, 2, (unix_time >> 24)::BIT(8)::INTEGER);
|
||||||
|
timestamp = SET_BYTE(timestamp, 3, (unix_time >> 16)::BIT(8)::INTEGER);
|
||||||
|
timestamp = SET_BYTE(timestamp, 4, (unix_time >> 8)::BIT(8)::INTEGER);
|
||||||
|
timestamp = SET_BYTE(timestamp, 5, unix_time::BIT(8)::INTEGER);
|
||||||
|
|
||||||
|
-- 10 entropy bytes
|
||||||
|
ulid = timestamp || gen_random_bytes(10);
|
||||||
|
|
||||||
|
-- Encode the timestamp
|
||||||
|
output = output || CHR(GET_BYTE(encoding, (GET_BYTE(ulid, 0) & 224) >> 5));
|
||||||
|
output = output || CHR(GET_BYTE(encoding, (GET_BYTE(ulid, 0) & 31)));
|
||||||
|
output = output || CHR(GET_BYTE(encoding, (GET_BYTE(ulid, 1) & 248) >> 3));
|
||||||
|
output = output || CHR(GET_BYTE(encoding, ((GET_BYTE(ulid, 1) & 7) << 2) | ((GET_BYTE(ulid, 2) & 192) >> 6)));
|
||||||
|
output = output || CHR(GET_BYTE(encoding, (GET_BYTE(ulid, 2) & 62) >> 1));
|
||||||
|
output = output || CHR(GET_BYTE(encoding, ((GET_BYTE(ulid, 2) & 1) << 4) | ((GET_BYTE(ulid, 3) & 240) >> 4)));
|
||||||
|
output = output || CHR(GET_BYTE(encoding, ((GET_BYTE(ulid, 3) & 15) << 1) | ((GET_BYTE(ulid, 4) & 128) >> 7)));
|
||||||
|
output = output || CHR(GET_BYTE(encoding, (GET_BYTE(ulid, 4) & 124) >> 2));
|
||||||
|
output = output || CHR(GET_BYTE(encoding, ((GET_BYTE(ulid, 4) & 3) << 3) | ((GET_BYTE(ulid, 5) & 224) >> 5)));
|
||||||
|
output = output || CHR(GET_BYTE(encoding, (GET_BYTE(ulid, 5) & 31)));
|
||||||
|
|
||||||
|
-- Encode the entropy
|
||||||
|
output = output || CHR(GET_BYTE(encoding, (GET_BYTE(ulid, 6) & 248) >> 3));
|
||||||
|
output = output || CHR(GET_BYTE(encoding, ((GET_BYTE(ulid, 6) & 7) << 2) | ((GET_BYTE(ulid, 7) & 192) >> 6)));
|
||||||
|
output = output || CHR(GET_BYTE(encoding, (GET_BYTE(ulid, 7) & 62) >> 1));
|
||||||
|
output = output || CHR(GET_BYTE(encoding, ((GET_BYTE(ulid, 7) & 1) << 4) | ((GET_BYTE(ulid, 8) & 240) >> 4)));
|
||||||
|
output = output || CHR(GET_BYTE(encoding, ((GET_BYTE(ulid, 8) & 15) << 1) | ((GET_BYTE(ulid, 9) & 128) >> 7)));
|
||||||
|
output = output || CHR(GET_BYTE(encoding, (GET_BYTE(ulid, 9) & 124) >> 2));
|
||||||
|
output = output || CHR(GET_BYTE(encoding, ((GET_BYTE(ulid, 9) & 3) << 3) | ((GET_BYTE(ulid, 10) & 224) >> 5)));
|
||||||
|
output = output || CHR(GET_BYTE(encoding, (GET_BYTE(ulid, 10) & 31)));
|
||||||
|
output = output || CHR(GET_BYTE(encoding, (GET_BYTE(ulid, 11) & 248) >> 3));
|
||||||
|
output = output || CHR(GET_BYTE(encoding, ((GET_BYTE(ulid, 11) & 7) << 2) | ((GET_BYTE(ulid, 12) & 192) >> 6)));
|
||||||
|
output = output || CHR(GET_BYTE(encoding, (GET_BYTE(ulid, 12) & 62) >> 1));
|
||||||
|
output = output || CHR(GET_BYTE(encoding, ((GET_BYTE(ulid, 12) & 1) << 4) | ((GET_BYTE(ulid, 13) & 240) >> 4)));
|
||||||
|
output = output || CHR(GET_BYTE(encoding, ((GET_BYTE(ulid, 13) & 15) << 1) | ((GET_BYTE(ulid, 14) & 128) >> 7)));
|
||||||
|
output = output || CHR(GET_BYTE(encoding, (GET_BYTE(ulid, 14) & 124) >> 2));
|
||||||
|
output = output || CHR(GET_BYTE(encoding, ((GET_BYTE(ulid, 14) & 3) << 3) | ((GET_BYTE(ulid, 15) & 224) >> 5)));
|
||||||
|
output = output || CHR(GET_BYTE(encoding, (GET_BYTE(ulid, 15) & 31)));
|
||||||
|
|
||||||
|
RETURN output;
|
||||||
|
END
|
||||||
|
$$
|
||||||
|
LANGUAGE plpgsql
|
||||||
|
VOLATILE;
|
||||||
|
|
||||||
|
-- migrate:down
|
||||||
|
|
||||||
|
DROP FUNCTION generate_ulid;
|
||||||
Reference in New Issue
Block a user