mirror of
https://github.com/filecoin-project/slate.git
synced 2024-09-17 17:27:52 +03:00
updated length of varchar for database cols to 200
This commit is contained in:
parent
42fe6545d4
commit
4ae04243cc
@ -112,8 +112,8 @@ const printFilesTable = async () => {
|
|||||||
/* Add columns (including tags) */
|
/* Add columns (including tags) */
|
||||||
|
|
||||||
const createSurveysTable = async () => {
|
const createSurveysTable = async () => {
|
||||||
await db.schema.createTable("surveys", function (table) {
|
await DB.schema.createTable("surveys", function (table) {
|
||||||
table.uuid("id").primary().unique().notNullable().defaultTo(db.raw("uuid_generate_v4()"));
|
table.uuid("id").primary().unique().notNullable().defaultTo(DB.raw("uuid_generate_v4()"));
|
||||||
table.uuid("ownerId").references("id").inTable("users");
|
table.uuid("ownerId").references("id").inTable("users");
|
||||||
|
|
||||||
// What do you currently use for saving things on the web?
|
// What do you currently use for saving things on the web?
|
||||||
@ -169,6 +169,15 @@ const addSlateColumns = async () => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//apply this to all other databases as well
|
||||||
|
const alterFileColumns = async () => {
|
||||||
|
await DB.schema.alterTable("files", function (table) {
|
||||||
|
table.string("linkImage", 2000).nullable().alter();
|
||||||
|
table.string("url", 2000).nullable().alter();
|
||||||
|
table.string("linkFavicon", 2000).nullable().alter();
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
const addFileColumns = async () => {
|
const addFileColumns = async () => {
|
||||||
await DB.schema.table("files", function (table) {
|
await DB.schema.table("files", function (table) {
|
||||||
table.renameColumn("data", "oldData");
|
table.renameColumn("data", "oldData");
|
||||||
@ -186,8 +195,8 @@ const addFileColumns = async () => {
|
|||||||
table.string("linkAuthor").nullable();
|
table.string("linkAuthor").nullable();
|
||||||
table.string("linkSource").nullable();
|
table.string("linkSource").nullable();
|
||||||
table.string("linkDomain").nullable();
|
table.string("linkDomain").nullable();
|
||||||
table.string("linkImage").nullable();
|
table.string("linkImage", 2000).nullable();
|
||||||
table.string("linkFavicon").nullable();
|
table.string("linkFavicon", 2000).nullable();
|
||||||
table.text("linkHtml").nullable();
|
table.text("linkHtml").nullable();
|
||||||
table.boolean("linkIFrameAllowed").nullable().defaultTo(false);
|
table.boolean("linkIFrameAllowed").nullable().defaultTo(false);
|
||||||
table.jsonb("tags").nullable();
|
table.jsonb("tags").nullable();
|
||||||
@ -211,12 +220,16 @@ const defaultBody = ["A user of Slate.", "", "A slate."];
|
|||||||
|
|
||||||
const migrateUserTable = async () => {
|
const migrateUserTable = async () => {
|
||||||
const users = await DB.select("id", "data").from("users");
|
const users = await DB.select("id", "data").from("users");
|
||||||
|
let count = 0;
|
||||||
for (let user of users) {
|
for (let user of users) {
|
||||||
|
if (count % 1000 === 0) {
|
||||||
|
console.log(count);
|
||||||
|
}
|
||||||
|
count += 1;
|
||||||
let data = user.data;
|
let data = user.data;
|
||||||
|
|
||||||
let newUser = {
|
let newUser = {
|
||||||
name: data.name,
|
name: data.name,
|
||||||
body: data.body,
|
body: data.body.slice(0, 2000),
|
||||||
photo: data.photo,
|
photo: data.photo,
|
||||||
textileKey: data.tokens?.api,
|
textileKey: data.tokens?.api,
|
||||||
twitterUsername: data.twitter?.username,
|
twitterUsername: data.twitter?.username,
|
||||||
@ -232,19 +245,24 @@ const migrateUserTable = async () => {
|
|||||||
newUser.body = null;
|
newUser.body = null;
|
||||||
}
|
}
|
||||||
// console.log({ data });
|
// console.log({ data });
|
||||||
console.log({ id: user.id, newUser });
|
// console.log({ id: user.id, newUser });
|
||||||
const response = await DB.from("users").where("id", user.id).update(newUser).returning("*");
|
const response = await DB.from("users").where("id", user.id).update(newUser).returning("*");
|
||||||
// console.log({ response });
|
// console.log({ response });
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const migrateSlateTable = async () => {
|
const deleteEmptySlates = async () => {
|
||||||
await DB("slates")
|
let emptySlates = await DB("slates")
|
||||||
|
.select("id")
|
||||||
.whereNotExists(function () {
|
.whereNotExists(function () {
|
||||||
this.select("id").from("slate_files").whereRaw('"slate_files"."slateId" = "slates"."id"');
|
this.select("id").from("slate_files").whereRaw('"slate_files"."slateId" = "slates"."id"');
|
||||||
})
|
});
|
||||||
.del();
|
for (let slate of emptySlates) {
|
||||||
|
await Data.deleteSlateById(slate);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const migrateSlateTable = async () => {
|
||||||
const slateFiles = () =>
|
const slateFiles = () =>
|
||||||
DB.raw("coalesce(json_agg(?? order by ?? asc) filter (where ?? is not null), '[]') as ??", [
|
DB.raw("coalesce(json_agg(?? order by ?? asc) filter (where ?? is not null), '[]') as ??", [
|
||||||
"files",
|
"files",
|
||||||
@ -265,7 +283,7 @@ const migrateSlateTable = async () => {
|
|||||||
let data = slate.data;
|
let data = slate.data;
|
||||||
let newSlate = {
|
let newSlate = {
|
||||||
name: data.name,
|
name: data.name,
|
||||||
body: data.body,
|
body: data.body ? data.body.slice(0, 2000) : null,
|
||||||
coverImage,
|
coverImage,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -281,8 +299,11 @@ const migrateSlateTable = async () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const migrateFileTable = async () => {
|
const migrateFileTable = async () => {
|
||||||
const files = await DB.select("id", "oldData").from("files");
|
const files = await DB.select("id", "oldData").from("files").where({ size: 0 });
|
||||||
|
let count = 0;
|
||||||
for (let file of files) {
|
for (let file of files) {
|
||||||
|
console.log(count);
|
||||||
|
count += 1;
|
||||||
let data = file.oldData;
|
let data = file.oldData;
|
||||||
if (!data) {
|
if (!data) {
|
||||||
console.log(`no data for file with id ${file.id}`);
|
console.log(`no data for file with id ${file.id}`);
|
||||||
@ -290,18 +311,18 @@ const migrateFileTable = async () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let newFile = {
|
let newFile = {
|
||||||
name: data.name,
|
name: data.name ? data.name.slice(0, 255) : null,
|
||||||
body: data.body,
|
body: data.body ? data.body.slice(0, 2000) : null,
|
||||||
size: data.size,
|
size: Math.min(data.size, 2147483647),
|
||||||
type: data.type,
|
type: data.type,
|
||||||
blurhash: data.blurhash,
|
blurhash: !data.blurhash || data.blurhash.length > 40 ? null : data.blurhash,
|
||||||
linkName: data.link?.name,
|
linkName: data.link?.name ? data.link?.name.slice(0, 255) : null,
|
||||||
linkBody: data.link?.body,
|
linkBody: data.link?.body ? data.link?.body.slice(0, 2000) : null,
|
||||||
linkAuthor: data.link?.author,
|
linkAuthor: data.link?.author ? data.link?.author.slice(0, 255) : null,
|
||||||
linkSource: data.link?.source,
|
linkSource: data.link?.source ? data.link?.source.slice(0, 255) : null,
|
||||||
linkDomain: data.link?.domain,
|
linkDomain: data.link?.domain,
|
||||||
linkImage: data.link?.image,
|
linkImage: !data.link?.image || data.link?.image.length > 2000 ? null : data.link?.image,
|
||||||
linkFavicon: data.link?.logo,
|
linkFavicon: !data.link?.logo || data.link?.logo.length > 2000 ? null : data.link?.logo,
|
||||||
linkHtml: data.link?.html,
|
linkHtml: data.link?.html,
|
||||||
linkIFrameAllowed: data.link?.iFrameAllowed,
|
linkIFrameAllowed: data.link?.iFrameAllowed,
|
||||||
};
|
};
|
||||||
@ -336,15 +357,16 @@ const migrateFileTable = async () => {
|
|||||||
this.select("id")
|
this.select("id")
|
||||||
.from("slate_files")
|
.from("slate_files")
|
||||||
.whereRaw('"slate_files"."slateId" = "slates"."id"')
|
.whereRaw('"slate_files"."slateId" = "slates"."id"')
|
||||||
.where({ "slate_files.fileId": fileId });
|
.where({ "slate_files.fileId": file.id });
|
||||||
});
|
});
|
||||||
|
|
||||||
if (tags?.length) {
|
if (tags?.length) {
|
||||||
newFile.tags = JSON.stringify(tags);
|
newFile.tags = JSON.stringify(tags);
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log({ newFile });
|
// console.log({ newFile });
|
||||||
const response = await DB.from("files").where("id", file.id).update(newFile);
|
const response = await DB.from("files").where("id", file.id).update(newFile).returning("*");
|
||||||
|
console.log(response);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -373,7 +395,9 @@ const runScript = async () => {
|
|||||||
// await addSlateColumns();
|
// await addSlateColumns();
|
||||||
// await addFileColumns();
|
// await addFileColumns();
|
||||||
|
|
||||||
// await migrateUserTable();
|
// await alterFileColumns();
|
||||||
|
await migrateUserTable();
|
||||||
|
// await deleteEmptySlates();
|
||||||
// await migrateSlateTable();
|
// await migrateSlateTable();
|
||||||
// await migrateFileTable();
|
// await migrateFileTable();
|
||||||
|
|
||||||
|
@ -88,7 +88,7 @@ const createFilesTable = createTableIfNotExists("files", function (table) {
|
|||||||
table.string("filename").nullable();
|
table.string("filename").nullable();
|
||||||
table.boolean("isPublic").notNullable().defaultTo(false);
|
table.boolean("isPublic").notNullable().defaultTo(false);
|
||||||
table.string("name").nullable();
|
table.string("name").nullable();
|
||||||
table.integer("size").notNullable().defaultTo(0);
|
table.bigInteger("size").notNullable().defaultTo(0);
|
||||||
table.string("type").notNullable().defaultTo("link");
|
table.string("type").notNullable().defaultTo("link");
|
||||||
table.string("blurhash").nullable();
|
table.string("blurhash").nullable();
|
||||||
table.string("body", 2000).nullable();
|
table.string("body", 2000).nullable();
|
||||||
@ -99,14 +99,14 @@ const createFilesTable = createTableIfNotExists("files", function (table) {
|
|||||||
table.string("linkAuthor").nullable();
|
table.string("linkAuthor").nullable();
|
||||||
table.string("linkSource").nullable();
|
table.string("linkSource").nullable();
|
||||||
table.string("linkDomain").nullable();
|
table.string("linkDomain").nullable();
|
||||||
table.string("linkImage").nullable();
|
table.string("linkImage", 2000).nullable();
|
||||||
table.string("linkFavicon").nullable();
|
table.string("linkFavicon", 2000).nullable();
|
||||||
table.text("linkHtml").nullable();
|
table.text("linkHtml").nullable();
|
||||||
table.boolean("linkIFrameAllowed").nullable().defaultTo(false);
|
table.boolean("linkIFrameAllowed").nullable().defaultTo(false);
|
||||||
table.jsonb("tags").nullable();
|
table.jsonb("tags").nullable();
|
||||||
table.integer("downloadCount").notNullable().defaultTo(0);
|
table.integer("downloadCount").notNullable().defaultTo(0);
|
||||||
table.integer("saveCount").notNullable().defaultTo(0);
|
table.integer("saveCount").notNullable().defaultTo(0);
|
||||||
table.string("url").nullable();
|
table.string("url", 2000).nullable();
|
||||||
table.boolean("isLink").notNullable().defaultTo(false);
|
table.boolean("isLink").notNullable().defaultTo(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user