add: move upload server to buckets
This commit is contained in:
parent
8116307ba0
commit
75fe720f21
83 changed files with 351 additions and 458 deletions
2
manual_migrations/apps_api_key.sql
Normal file
2
manual_migrations/apps_api_key.sql
Normal file
|
@ -0,0 +1,2 @@
|
|||
ALTER TABLE apps
|
||||
ADD COLUMN api_key TEXT NOT NULL DEFAULT '';
|
2
manual_migrations/apps_data_used.sql
Normal file
2
manual_migrations/apps_data_used.sql
Normal file
|
@ -0,0 +1,2 @@
|
|||
ALTER TABLE apps
|
||||
ADD COLUMN data_used INT NOT NULL DEFAULT 0 CHECK (data_used >= 0);
|
2
manual_migrations/apps_scopes.sql
Normal file
2
manual_migrations/apps_scopes.sql
Normal file
|
@ -0,0 +1,2 @@
|
|||
ALTER TABLE apps
|
||||
ADD COLUMN scopes TEXT NOT NULL DEFAULT '[]';
|
2
manual_migrations/browser_session.sql
Normal file
2
manual_migrations/browser_session.sql
Normal file
|
@ -0,0 +1,2 @@
|
|||
ALTER TABLE users
|
||||
ADD COLUMN browser_session TEXT NOT NULL DEFAULT '';
|
2
manual_migrations/channels_last_message.sql
Normal file
2
manual_migrations/channels_last_message.sql
Normal file
|
@ -0,0 +1,2 @@
|
|||
ALTER TABLE channels
|
||||
ADD COLUMN last_message BIGINT NOT NULL DEFAULT '0';
|
2
manual_migrations/channels_members.sql
Normal file
2
manual_migrations/channels_members.sql
Normal file
|
@ -0,0 +1,2 @@
|
|||
ALTER TABLE channels
|
||||
ADD COLUMN members TEXT NOT NULL DEFAULT '[]';
|
2
manual_migrations/channels_title.sql
Normal file
2
manual_migrations/channels_title.sql
Normal file
|
@ -0,0 +1,2 @@
|
|||
ALTER TABLE channels
|
||||
ADD COLUMN title TEXT NOT NULL DEFAULT '';
|
2
manual_migrations/communities_is_forge.sql
Normal file
2
manual_migrations/communities_is_forge.sql
Normal file
|
@ -0,0 +1,2 @@
|
|||
ALTER TABLE communities
|
||||
ADD COLUMN is_forge INT NOT NULL DEFAULT 0;
|
2
manual_migrations/communities_post_count.sql
Normal file
2
manual_migrations/communities_post_count.sql
Normal file
|
@ -0,0 +1,2 @@
|
|||
ALTER TABLE communities
|
||||
ADD COLUMN post_count INT NOT NULL DEFAULT 0;
|
2
manual_migrations/journals_dirs.sql
Normal file
2
manual_migrations/journals_dirs.sql
Normal file
|
@ -0,0 +1,2 @@
|
|||
ALTER TABLE journals
|
||||
ADD COLUMN dirs TEXT NOT NULL DEFAULT '[]';
|
2
manual_migrations/messages_reactions.sql
Normal file
2
manual_migrations/messages_reactions.sql
Normal file
|
@ -0,0 +1,2 @@
|
|||
ALTER TABLE messages
|
||||
ADD COLUMN reactions TEXT NOT NULL DEFAULT '{}';
|
5
manual_migrations/notes_dir_tags.sql
Normal file
5
manual_migrations/notes_dir_tags.sql
Normal file
|
@ -0,0 +1,5 @@
|
|||
ALTER TABLE notes
|
||||
ADD COLUMN dir BIGINT NOT NULL DEFAULT 0;
|
||||
|
||||
ALTER TABLE notes
|
||||
ADD COLUMN tags TEXT NOT NULL DEFAULT '[]';
|
2
manual_migrations/notes_is_global.sql
Normal file
2
manual_migrations/notes_is_global.sql
Normal file
|
@ -0,0 +1,2 @@
|
|||
ALTER TABLE notes
|
||||
ADD COLUMN is_global INT NOT NULL DEFAULT 0;
|
7
manual_migrations/notifications_tag.sql
Normal file
7
manual_migrations/notifications_tag.sql
Normal file
|
@ -0,0 +1,7 @@
|
|||
-- remove users subscriptions
|
||||
ALTER TABLE users
|
||||
DROP COLUMN subscriptions;
|
||||
|
||||
-- add notifications tag
|
||||
ALTER TABLE notifications
|
||||
ADD COLUMN tag TEXT NOT NULL DEFAULT '';
|
2
manual_migrations/posts_is_deleted.sql
Normal file
2
manual_migrations/posts_is_deleted.sql
Normal file
|
@ -0,0 +1,2 @@
|
|||
ALTER TABLE posts
|
||||
ADD COLUMN is_deleted INT NOT NULL DEFAULT 0;
|
2
manual_migrations/posts_is_open.sql
Normal file
2
manual_migrations/posts_is_open.sql
Normal file
|
@ -0,0 +1,2 @@
|
|||
ALTER TABLE posts
|
||||
ADD COLUMN is_open INT NOT NULL DEFAULT 1;
|
2
manual_migrations/posts_poll_id.sql
Normal file
2
manual_migrations/posts_poll_id.sql
Normal file
|
@ -0,0 +1,2 @@
|
|||
ALTER TABLE posts
|
||||
ADD COLUMN poll_id BIGINT NOT NULL DEFAULT 0;
|
5
manual_migrations/posts_stack.sql
Normal file
5
manual_migrations/posts_stack.sql
Normal file
|
@ -0,0 +1,5 @@
|
|||
ALTER TABLE posts
|
||||
DROP COLUMN circle;
|
||||
|
||||
ALTER TABLE posts
|
||||
ADD COLUMN stack BIGINT NOT NULL DEFAULT 0;
|
2
manual_migrations/posts_title.sql
Normal file
2
manual_migrations/posts_title.sql
Normal file
|
@ -0,0 +1,2 @@
|
|||
ALTER TABLE posts
|
||||
ADD COLUMN title TEXT NOT NULL DEFAULT '';
|
4
manual_migrations/posts_tscvector_content.sql
Normal file
4
manual_migrations/posts_tscvector_content.sql
Normal file
|
@ -0,0 +1,4 @@
|
|||
ALTER TABLE posts
|
||||
ADD COLUMN tsvector_content tsvector GENERATED ALWAYS AS (to_tsvector ('english', coalesce(content, ''))) STORED;
|
||||
|
||||
CREATE INDEX tsvector_content_idx ON posts USING GIN (tsvector_content);
|
2
manual_migrations/posts_uploads.sql
Normal file
2
manual_migrations/posts_uploads.sql
Normal file
|
@ -0,0 +1,2 @@
|
|||
ALTER TABLE posts
|
||||
ADD COLUMN uploads TEXT NOT NULL DEFAULT '[]';
|
2
manual_migrations/questions_context.sql
Normal file
2
manual_migrations/questions_context.sql
Normal file
|
@ -0,0 +1,2 @@
|
|||
ALTER TABLE questions
|
||||
ADD COLUMN context TEXT NOT NULL DEFAULT '{}';
|
2
manual_migrations/questions_drawings.sql
Normal file
2
manual_migrations/questions_drawings.sql
Normal file
|
@ -0,0 +1,2 @@
|
|||
ALTER TABLE questions
|
||||
ADD COLUMN drawings TEXT NOT NULL DEFAULT '[]';
|
2
manual_migrations/questions_ip.sql
Normal file
2
manual_migrations/questions_ip.sql
Normal file
|
@ -0,0 +1,2 @@
|
|||
ALTER TABLE questions
|
||||
ADD COLUMN ip TEXT NOT NULL DEFAULT '';
|
5
manual_migrations/questions_likes.sql
Normal file
5
manual_migrations/questions_likes.sql
Normal file
|
@ -0,0 +1,5 @@
|
|||
ALTER TABLE questions
|
||||
ADD COLUMN likes INT NOT NULL DEFAULT 0;
|
||||
|
||||
ALTER TABLE questions
|
||||
ADD COLUMN dislikes INT NOT NULL DEFAULT 0;
|
1
manual_migrations/reactions_unique.sql
Normal file
1
manual_migrations/reactions_unique.sql
Normal file
|
@ -0,0 +1 @@
|
|||
ALTER TABLE reactions ADD CONSTRAINT uq_reactions UNIQUE (owner, asset);
|
2
manual_migrations/requests_pkey.sql
Normal file
2
manual_migrations/requests_pkey.sql
Normal file
|
@ -0,0 +1,2 @@
|
|||
ALTER TABLE requests
|
||||
DROP CONSTRAINT requests_pkey;
|
1
manual_migrations/requests_pkeys.sql
Normal file
1
manual_migrations/requests_pkeys.sql
Normal file
|
@ -0,0 +1 @@
|
|||
ALTER TABLE requests ADD CONSTRAINT requests_pkey PRIMARY KEY (id, owner, linked_asset);
|
2
manual_migrations/services_revision.sql
Normal file
2
manual_migrations/services_revision.sql
Normal file
|
@ -0,0 +1,2 @@
|
|||
ALTER TABLE services
|
||||
ADD COLUMN revision BIGINT NOT NULL DEFAULT 0;
|
5
manual_migrations/stacks_mode_sort.sql
Normal file
5
manual_migrations/stacks_mode_sort.sql
Normal file
|
@ -0,0 +1,5 @@
|
|||
ALTER TABLE stacks
|
||||
ADD COLUMN mode TEXT NOT NULL DEFAULT '"Include"';
|
||||
|
||||
ALTER TABLE stacks
|
||||
ADD COLUMN sort TEXT NOT NULL DEFAULT '"Created"';
|
43
manual_migrations/uploads.js
Normal file
43
manual_migrations/uploads.js
Normal file
|
@ -0,0 +1,43 @@
|
|||
import postgres from "npm:postgres";
|
||||
import { parse } from "npm:smol-toml";
|
||||
|
||||
const config = parse(await Deno.readTextFile(Deno.cwd() + "/tetratto.toml"), {
|
||||
integersAsBigInt: true,
|
||||
});
|
||||
|
||||
const db = postgres({
|
||||
user: config.database.user,
|
||||
password: config.database.password,
|
||||
database: config.database.name,
|
||||
hostname: config.database.url.split(":")[0],
|
||||
port: config.database.url.split(":")[1],
|
||||
});
|
||||
|
||||
const whats = {};
|
||||
const alts = {};
|
||||
|
||||
for (const row of await db`SELECT * FROM uploads;`) {
|
||||
whats[row.id] = row.what.replaceAll('"', "");
|
||||
alts[row.id] = row.alt;
|
||||
}
|
||||
|
||||
await db`ALTER TABLE uploads DROP COLUMN IF EXISTS what;`;
|
||||
await db`ALTER TABLE uploads DROP COLUMN IF EXISTS alt;`;
|
||||
await db`ALTER TABLE uploads ADD COLUMN IF NOT EXISTS bucket TEXT NOT NULL DEFAULT '';`;
|
||||
await db`ALTER TABLE uploads ADD COLUMN IF NOT EXISTS metadata TEXT NOT NULL DEFAULT '';`;
|
||||
|
||||
let i = 0;
|
||||
for (const row of await db`SELECT * FROM uploads;`) {
|
||||
await db`DELETE FROM uploads WHERE id = ${BigInt(row.id)}`;
|
||||
await db`INSERT INTO uploads VALUES (${BigInt(row.id)}, ${BigInt(row.created)}, ${BigInt(row.owner)}, DEFAULT, ${JSON.stringify(
|
||||
{
|
||||
what: whats[row.id],
|
||||
alt: whats[row.alt],
|
||||
},
|
||||
)});`;
|
||||
|
||||
i += 1;
|
||||
console.log(`done ${i}`);
|
||||
}
|
||||
|
||||
await db.end();
|
2
manual_migrations/uploads_alt.sql
Normal file
2
manual_migrations/uploads_alt.sql
Normal file
|
@ -0,0 +1,2 @@
|
|||
ALTER TABLE uploads
|
||||
ADD COLUMN alt TEXT NOT NULL DEFAULT '';
|
2
manual_migrations/users_achievements.sql
Normal file
2
manual_migrations/users_achievements.sql
Normal file
|
@ -0,0 +1,2 @@
|
|||
ALTER TABLE users
|
||||
ADD COLUMN achievements TEXT NOT NULL DEFAULT '[]';
|
2
manual_migrations/users_associated.sql
Normal file
2
manual_migrations/users_associated.sql
Normal file
|
@ -0,0 +1,2 @@
|
|||
ALTER TABLE users
|
||||
ADD COLUMN associated TEXT NOT NULL DEFAULT '[]';
|
5
manual_migrations/users_awaiting_purchase.sql
Normal file
5
manual_migrations/users_awaiting_purchase.sql
Normal file
|
@ -0,0 +1,5 @@
|
|||
ALTER TABLE users
|
||||
ADD COLUMN awaiting_purchase INT NOT NULL DEFAULT 0;
|
||||
|
||||
ALTER TABLE users
|
||||
ADD COLUMN was_purchased INT NOT NULL DEFAULT 0;
|
2
manual_migrations/users_ban_reason.sql
Normal file
2
manual_migrations/users_ban_reason.sql
Normal file
|
@ -0,0 +1,2 @@
|
|||
ALTER TABLE users
|
||||
ADD COLUMN ban_reason TEXT NOT NULL DEFAULT '';
|
2
manual_migrations/users_connections.sql
Normal file
2
manual_migrations/users_connections.sql
Normal file
|
@ -0,0 +1,2 @@
|
|||
ALTER TABLE users
|
||||
ADD COLUMN connections TEXT NOT NULL DEFAULT '{}';
|
2
manual_migrations/users_grants.sql
Normal file
2
manual_migrations/users_grants.sql
Normal file
|
@ -0,0 +1,2 @@
|
|||
ALTER TABLE users
|
||||
ADD COLUMN grants TEXT NOT NULL DEFAULT '[]';
|
2
manual_migrations/users_invite_code.sql
Normal file
2
manual_migrations/users_invite_code.sql
Normal file
|
@ -0,0 +1,2 @@
|
|||
ALTER TABLE users
|
||||
ADD COLUMN invite_code BIGINT NOT NULL DEFAULT 0;
|
2
manual_migrations/users_layouts.sql
Normal file
2
manual_migrations/users_layouts.sql
Normal file
|
@ -0,0 +1,2 @@
|
|||
ALTER TABLE users
|
||||
DROP COLUMN layouts;
|
2
manual_migrations/users_post_count.sql
Normal file
2
manual_migrations/users_post_count.sql
Normal file
|
@ -0,0 +1,2 @@
|
|||
ALTER TABLE users
|
||||
ADD COLUMN post_count INT NOT NULL DEFAULT 0;
|
2
manual_migrations/users_request_count.sql
Normal file
2
manual_migrations/users_request_count.sql
Normal file
|
@ -0,0 +1,2 @@
|
|||
ALTER TABLE users
|
||||
ADD COLUMN request_count INT NOT NULL DEFAULT 0;
|
2
manual_migrations/users_secondary_permissions.sql
Normal file
2
manual_migrations/users_secondary_permissions.sql
Normal file
|
@ -0,0 +1,2 @@
|
|||
ALTER TABLE users
|
||||
ADD COLUMN secondary_permissions INT NOT NULL DEFAULT 1;
|
2
manual_migrations/users_seller_data.sql
Normal file
2
manual_migrations/users_seller_data.sql
Normal file
|
@ -0,0 +1,2 @@
|
|||
ALTER TABLE users
|
||||
ADD COLUMN seller_data TEXT NOT NULL DEFAULT '{}';
|
2
manual_migrations/users_stripe_id.sql
Normal file
2
manual_migrations/users_stripe_id.sql
Normal file
|
@ -0,0 +1,2 @@
|
|||
ALTER TABLE users
|
||||
ADD COLUMN stripe_id TEXT DEFAULT '';
|
5
manual_migrations/users_totp.sql
Normal file
5
manual_migrations/users_totp.sql
Normal file
|
@ -0,0 +1,5 @@
|
|||
ALTER TABLE users
|
||||
ADD COLUMN totp TEXT DEFAULT '';
|
||||
|
||||
ALTER TABLE users
|
||||
ADD COLUMN recovery_codes TEXT DEFAULT '[]';
|
Loading…
Add table
Add a link
Reference in a new issue