feat(DB/Surveys): update database scripts with the surveys table changes

This commit is contained in:
Aminejv 2021-12-29 09:50:53 +01:00
parent 1faaba264c
commit 5f893bb1f8
3 changed files with 74 additions and 51 deletions

View File

@ -2,18 +2,16 @@ import { runQuery } from "~/node_common/data/utilities";
export default async ({
ownerId,
prevToolsDropbox,
prevToolsArena,
prevToolsPinterest,
prevToolsGoogleDrive,
prevToolsBrowserBookmarks,
prevToolsPinterest,
prevToolsArena,
prevToolsNotesPlatform,
prevToolsOther,
useCasesPersonalStorage,
useCasesPublicFileSharing,
useCasesArchiving,
useCasesBookmarking,
useCasesMoodboarding,
useCasesBookmarkingImportantPages,
useCasesSavingLinksToReadLater,
useCasesSearchingYourBrowsedPages,
useCasesSharingCollectionsOfLinks,
useCasesOther,
referralFriend,
@ -26,19 +24,16 @@ export default async ({
queryFn: async (DB) => {
let query = await DB.insert({
ownerId,
prevToolsDropbox,
prevToolsArena,
prevToolsPinterest,
prevToolsGoogleDrive,
prevToolsBrowserBookmarks,
prevToolsPinterest,
prevToolsArena,
prevToolsNotesPlatform,
prevToolsOther,
useCasesPersonalStorage,
useCasesPublicFileSharing,
useCasesArchiving,
useCasesBookmarking,
useCasesMoodboarding,
useCasesBookmarkingImportantPages,
useCasesSavingLinksToReadLater,
useCasesSearchingYourBrowsedPages,
useCasesSharingCollectionsOfLinks,
useCasesOther,
referralFriend,

View File

@ -11,6 +11,15 @@ 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);
});
}
};
const renameDealsTable = db.schema.renameTable("deals", "old_deals");
const deleteGlobalTable = db.schema.dropTable("global");
@ -42,32 +51,53 @@ const addSlateCoverImage = db.schema.table("slates", function (table) {
table.jsonb("coverImage").nullable();
});
const createSurveysTable = db.schema.table("surveys", function (table) {
table.uuid("id").primary().unique().notNullable().defaultTo(db.raw("uuid_generate_v4()"));
table.uuid("ownerId").references("id").inTable("users");
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);
// What do you currently use for saving things on the web?
table.boolean("prevToolsDropbox").defaultTo(false);
table.boolean("prevToolsArena").defaultTo(false);
table.boolean("prevToolsPinterest").defaultTo(false);
table.boolean("prevToolsGoogleDrive").defaultTo(false);
table.boolean("prevToolsBrowserBookmarks").defaultTo(false);
table.string("prevToolsOther").defaultTo(null);
table.boolean("useCasesBookmarkingImportantPages").defaultTo(false);
table.boolean("useCasesSavingLinksToReadLater").defaultTo(false);
table.boolean("useCasesSearchingYourBrowsedPages").defaultTo(false);
table.boolean("useCasesSharingCollectionsOfLinks").defaultTo(false);
}),
]);
}
// What are you interested in using Slate for?
table.boolean("useCasesPersonalStorage").defaultTo(false);
table.boolean("useCasesPublicFileSharing").defaultTo(false);
table.boolean("useCasesArchiving").defaultTo(false);
table.boolean("useCasesBookmarking").defaultTo(false);
table.boolean("useCasesMoodboarding").defaultTo(false);
table.string("useCasesOther").defaultTo(null);
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");
// 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);
});
// 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);
});
})();
const dropOnboardingTable = db.schema.dropTableIfExists("onboarding");
const addOnboardingColumnsToUsersTable = db.schema.table("users", function (table) {

View File

@ -192,19 +192,17 @@ const createSurveysTable = createTableIfNotExists("surveys", function (table) {
table.uuid("ownerId").references("id").inTable("users");
// What do you currently use for saving things on the web?
table.boolean("prevToolsDropbox").defaultTo(false);
table.boolean("prevToolsArena").defaultTo(false);
table.boolean("prevToolsPinterest").defaultTo(false);
table.boolean("prevToolsGoogleDrive").defaultTo(false);
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("useCasesPersonalStorage").defaultTo(false);
table.boolean("useCasesPublicFileSharing").defaultTo(false);
table.boolean("useCasesArchiving").defaultTo(false);
table.boolean("useCasesBookmarking").defaultTo(false);
table.boolean("useCasesMoodboarding").defaultTo(false);
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?