diff --git a/node_common/data/methods/create-survey.js b/node_common/data/methods/create-survey.js index 80b472b2..35062709 100644 --- a/node_common/data/methods/create-survey.js +++ b/node_common/data/methods/create-survey.js @@ -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, diff --git a/scripts/adjust.js b/scripts/adjust.js index 09d32fde..6745f941 100644 --- a/scripts/adjust.js +++ b/scripts/adjust.js @@ -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) { diff --git a/scripts/seed-database.js b/scripts/seed-database.js index 7241bd86..1b774602 100644 --- a/scripts/seed-database.js +++ b/scripts/seed-database.js @@ -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?