2021-06-11 22:25:58 +03:00
|
|
|
import * as Logging from "~/common/logging";
|
|
|
|
|
2020-07-27 01:37:12 +03:00
|
|
|
import configs from "~/knexfile";
|
|
|
|
import knex from "knex";
|
|
|
|
|
|
|
|
const envConfig = configs["development"];
|
|
|
|
|
2021-06-11 22:25:58 +03:00
|
|
|
Logging.log(`SETUP: database`, envConfig);
|
2020-07-27 01:37:12 +03:00
|
|
|
|
|
|
|
const db = knex(envConfig);
|
|
|
|
|
2021-06-11 22:25:58 +03:00
|
|
|
Logging.log(`RUNNING: adjust.js`);
|
2020-07-27 01:37:12 +03:00
|
|
|
|
2021-12-29 11:50:53 +03:00
|
|
|
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) {
|
2021-09-28 23:52:21 +03:00
|
|
|
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
|
|
|
});
|
|
|
|
|
2021-09-29 00:54:02 +03:00
|
|
|
const deleteStorageDealSettings = db.schema.table("users", function (table) {
|
|
|
|
table.dropColumns(
|
|
|
|
"settingsDealsAutoApprove",
|
|
|
|
"allowEncryptedDataStorage",
|
|
|
|
"allowAutomaticDataStorage"
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2021-11-12 00:11:13 +03:00
|
|
|
const deleteSourceAndAuthor = db.schema.table("files", function (table) {
|
|
|
|
table.dropColumns("source", "author");
|
|
|
|
});
|
|
|
|
|
2021-11-13 04:50:20 +03:00
|
|
|
const addSlateCoverImage = db.schema.table("slates", function (table) {
|
|
|
|
table.dropColumns("preview");
|
|
|
|
table.jsonb("coverImage").nullable();
|
|
|
|
});
|
|
|
|
|
2022-01-28 02:24:22 +03:00
|
|
|
const dropOnboardingColumn = db.schema.table("users", function (table) {
|
|
|
|
table.dropColumn("onboarding");
|
|
|
|
});
|
|
|
|
|
|
|
|
const createSurveysTable = async () => {
|
2021-12-29 11:50:53 +03:00
|
|
|
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);
|
|
|
|
});
|
2022-01-28 02:24:22 +03:00
|
|
|
};
|
2021-12-09 14:27:18 +03:00
|
|
|
|
2021-12-20 19:06:16 +03:00
|
|
|
const dropOnboardingTable = db.schema.dropTableIfExists("onboarding");
|
2022-01-03 14:24:34 +03:00
|
|
|
|
2021-12-20 19:06:16 +03:00
|
|
|
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
|
|
|
|
2022-01-03 14:24:34 +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);
|
|
|
|
});
|
|
|
|
|
2022-09-19 20:18:45 +03:00
|
|
|
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);
|
|
|
|
});
|
|
|
|
|
2022-01-28 02:24:22 +03:00
|
|
|
// Promise.all([
|
|
|
|
// dropOnboardingTable,
|
|
|
|
// createSurveysTable,
|
|
|
|
// addOnboardingColumnsToUsersTable,
|
|
|
|
// deleteSettingsColumnFromUserTable,
|
|
|
|
// addIsFilterSidebarCollapsedToUsersTable,
|
|
|
|
// ]);
|
|
|
|
|
2022-09-19 20:18:45 +03:00
|
|
|
Promise.all([addExtensionColumnsToUsersTable]);
|
2020-07-27 01:37:12 +03:00
|
|
|
|
2021-06-11 22:25:58 +03:00
|
|
|
Logging.log(`FINISHED: adjust.js`);
|
|
|
|
Logging.log(` CTRL +C to return to terminal.`);
|