slate/scripts/adjust.js

147 lines
5.3 KiB
JavaScript
Raw Normal View History

import * as Logging from "~/common/logging";
import configs from "~/knexfile";
import knex from "knex";
const envConfig = configs["development"];
Logging.log(`SETUP: database`, envConfig);
const db = knex(envConfig);
Logging.log(`RUNNING: adjust.js`);
const dropColumnIfExists = async (tableName, columnName) => {
const hasColumn = await db.schema.hasColumn(tableName, columnName);
if (hasColumn) {
return db.schema.alterTable(tableName, (table) => {
table.dropColumn(columnName);
});
}
};
2021-09-27 03:19:40 +03:00
const renameDealsTable = db.schema.renameTable("deals", "old_deals");
2021-05-25 01:19:48 +03:00
2021-09-27 03:19:40 +03:00
const deleteGlobalTable = db.schema.dropTable("global");
2021-05-25 01:19:48 +03:00
2021-09-27 03:19:40 +03:00
const deleteStatsTable = db.schema.dropTable("stats");
2021-05-25 01:19:48 +03:00
2021-09-27 03:19:40 +03:00
const createDealsTable = db.schema.createTable("deals", function (table) {
table.uuid("id").primary().unique().notNullable().defaultTo(db.raw("uuid_generate_v4()"));
table.string("textileBucketCID").notNullable();
table.string("pinCID").notNullable();
table.string("requestId").notNullable();
2021-09-27 03:19:40 +03:00
table.timestamp("createdAt").notNullable().defaultTo(db.raw("now()"));
2021-05-25 01:19:48 +03:00
});
const deleteStorageDealSettings = db.schema.table("users", function (table) {
table.dropColumns(
"settingsDealsAutoApprove",
"allowEncryptedDataStorage",
"allowAutomaticDataStorage"
);
});
const deleteSourceAndAuthor = db.schema.table("files", function (table) {
table.dropColumns("source", "author");
});
const addSlateCoverImage = db.schema.table("slates", function (table) {
table.dropColumns("preview");
table.jsonb("coverImage").nullable();
});
const dropOnboardingColumn = db.schema.table("users", function (table) {
table.dropColumn("onboarding");
});
const createSurveysTable = async () => {
const exists = await db.schema.hasTable("surveys");
if (exists) {
return Promise.all([
dropColumnIfExists("surveys", "prevToolsDropbox"),
dropColumnIfExists("surveys", "prevToolsGoogleDrive"),
dropColumnIfExists("surveys", "useCasesPersonalStorage"),
dropColumnIfExists("surveys", "useCasesPublicFileSharing"),
dropColumnIfExists("surveys", "useCasesArchiving"),
dropColumnIfExists("surveys", "useCasesBookmarking"),
dropColumnIfExists("surveys", "useCasesMoodboarding"),
db.schema.alterTable("surveys", (table) => {
table.boolean("prevToolsNotesPlatform").defaultTo(false);
table.boolean("useCasesBookmarkingImportantPages").defaultTo(false);
table.boolean("useCasesSavingLinksToReadLater").defaultTo(false);
table.boolean("useCasesSearchingYourBrowsedPages").defaultTo(false);
table.boolean("useCasesSharingCollectionsOfLinks").defaultTo(false);
}),
]);
}
return db.schema.createTable("surveys", function (table) {
table.uuid("id").primary().unique().notNullable().defaultTo(db.raw("uuid_generate_v4()"));
table.uuid("ownerId").references("id").inTable("users");
// What do you currently use for saving things on the web?
table.boolean("prevToolsBrowserBookmarks").defaultTo(false);
table.boolean("prevToolsPinterest").defaultTo(false);
table.boolean("prevToolsArena").defaultTo(false);
table.boolean("prevToolsNotesPlatform").defaultTo(false);
table.string("prevToolsOther").defaultTo(null);
// What are you interested in using Slate for?
table.boolean("useCasesBookmarkingImportantPages").defaultTo(false);
table.boolean("useCasesSavingLinksToReadLater").defaultTo(false);
table.boolean("useCasesSearchingYourBrowsedPages").defaultTo(false);
table.boolean("useCasesSharingCollectionsOfLinks").defaultTo(false);
table.string("useCasesOther").defaultTo(null);
// How did you find out about Slate?
table.boolean("referralFriend").defaultTo(false);
table.boolean("referralTwitter").defaultTo(false);
table.boolean("referralIpfsFilecoinCommunity").defaultTo(false);
table.string("referralOther").defaultTo(null);
});
};
2021-12-09 14:27:18 +03:00
const dropOnboardingTable = db.schema.dropTableIfExists("onboarding");
const addOnboardingColumnsToUsersTable = db.schema.table("users", function (table) {
table.boolean("hasCompletedSurvey").defaultTo(false);
table.boolean("hasCompletedUploadOnboarding").defaultTo(false);
table.boolean("hasCompletedSlatesOnboarding").defaultTo(false);
});
2021-12-09 18:27:59 +03:00
const deleteSettingsColumnFromUserTable = (async () => {
const hasColumn = await db.schema.hasColumn("users", "settings");
if (hasColumn) {
return db.schema.alterTable("users", (table) => {
table.dropColumn("settings");
});
}
})();
const addIsFilterSidebarCollapsedToUsersTable = db.schema.table("users", function (table) {
table.boolean("isFilterSidebarCollapsed").defaultTo(false);
});
const addExtensionColumnsToUsersTable = db.schema.table("users", function (table) {
table.boolean("isRecentViewActivated").defaultTo(false);
table.boolean("isFilesViewActivated").defaultTo(false);
table.boolean("hasCompletedExtensionOBFirstStep").defaultTo(false);
table.boolean("hasCompletedExtensionOBSecondStep").defaultTo(false);
table.boolean("hasCompletedExtensionOBThirdStep").defaultTo(false);
});
// Promise.all([
// dropOnboardingTable,
// createSurveysTable,
// addOnboardingColumnsToUsersTable,
// deleteSettingsColumnFromUserTable,
// addIsFilterSidebarCollapsedToUsersTable,
// ]);
Promise.all([addExtensionColumnsToUsersTable]);
Logging.log(`FINISHED: adjust.js`);
Logging.log(` CTRL +C to return to terminal.`);