diff --git a/dolt/block-is-upcoming.js b/dolt/block-is-upcoming.js new file mode 100644 index 00000000000000..03cb6aa5b9401a --- /dev/null +++ b/dolt/block-is-upcoming.js @@ -0,0 +1,24 @@ +import { readFileSync, readdirSync } from 'fs'; + +let upcomingBlocks = {}; +const metaPath = '../curriculum/challenges/_meta'; + +const filesToIgnore = ['.DS_Store']; + +try { + const metaDir = readdirSync(metaPath); + + metaDir.forEach(file => { + if (!filesToIgnore.includes(file)) { + const metaFile = readFileSync(`${metaPath}/${file}/meta.json`, 'utf8'); + const metaJson = JSON.parse(metaFile); + upcomingBlocks[metaJson.dashedName] = metaJson.isUpcomingChange; + } + }); +} catch (error) { + console.error('Error:', error); +} + +export const getBlockIsUpcoming = dashedName => { + return upcomingBlocks[dashedName]; +}; diff --git a/dolt/challenge-type-to-tables-map.js b/dolt/challenge-type-to-tables-map.js index f4cc51ea97e8a3..dcbdb30662ef62 100644 --- a/dolt/challenge-type-to-tables-map.js +++ b/dolt/challenge-type-to-tables-map.js @@ -1,33 +1,41 @@ import { challengeTypes } from '../shared/config/challenge-types.js'; import { insert } from './utils.js'; +const ids = { + app_url: 1, + source_code_url: 1, + local_address_allowed: 1, + editor_address_allowed: 1, + display_preview_modal: 1 +}; + const app_url = required => async (connection, challenge) => await insert( connection, 'app_url', - ['challenge_id', 'required'], - [challenge.id, required] + ['id', 'challenge_id', 'required'], + [ids.app_url++, challenge.id, required] ); const source_code_url = required => async (connection, challenge) => await insert( connection, 'source_code_url', - ['challenge_id', 'required'], - [challenge.id, required] + ['id', 'challenge_id', 'required'], + [ids.source_code_url++, challenge.id, required] ); const local_address_allowed = async (connection, challenge) => await insert( connection, 'local_address_allowed', - ['challenge_id'], - [challenge.id] + ['id', 'challenge_id'], + [ids.local_address_allowed++, challenge.id] ); const editor_address_allowed = async (connection, challenge) => await insert( connection, 'editor_address_allowed', - ['challenge_id'], - [challenge.id] + ['id', 'challenge_id'], + [ids.editor_address_allowed++, challenge.id] ); const display_preview_modal = async (connection, challenge) => { @@ -39,8 +47,8 @@ const display_preview_modal = async (connection, challenge) => { await insert( connection, 'display_preview_modal', - ['challenge_id'], - [challenge.id] + ['id', 'challenge_id'], + [ids.display_preview_modal++, challenge.id] ); } }; diff --git a/dolt/mysql.js b/dolt/mysql.js index 1134e2725d47b5..e645ce218deb72 100644 --- a/dolt/mysql.js +++ b/dolt/mysql.js @@ -7,6 +7,7 @@ import { } from './utils.js'; import { challengeTypeToTablesMap } from './challenge-type-to-tables-map.js'; import { getSuperblockTitle, getBlockTitle } from './dashed-names-to-titles.js'; +import { getBlockIsUpcoming } from './block-is-upcoming.js'; export async function withConnection(connectionString, callback) { const connection = createConnection(connectionString); @@ -97,6 +98,15 @@ CREATE TABLE IF NOT EXISTS block_time_to_complete( )`; await runCreateTable(connection, sql); + sql = ` + CREATE TABLE IF NOT EXISTS block_is_upcoming( + id INT NOT NULL AUTO_INCREMENT, + block_id INT NOT NULL, + PRIMARY KEY (id), + FOREIGN KEY (block_id) REFERENCES blocks(id) + )`; + await runCreateTable(connection, sql); + // Additional feature tables to replace challengeTypes sql = ` CREATE TABLE IF NOT EXISTS app_url( @@ -252,6 +262,7 @@ export async function addChallenges(connection, data) { const feature_table_ids = {}; let block_id = 1; let superblock_id = 1; + let block_is_upcoming_id = 1; let c = 1; for (const challengeNode of data) { @@ -304,14 +315,24 @@ export async function addChallenges(connection, data) { blockSet.add(block); block_to_block_id_map.set(block, block_id); - // Add `block_time_to_complete` as special case, because it is per-block + // Add `block_time_to_complete` and `block_is_upcoming` as special case, because it is per-block await insert( connection, 'block_time_to_complete', - ['block_id', 'time_to_complete'], - [block_id, time] + ['id', 'block_id', 'time_to_complete'], + [block_id, block_id, time] ); + const blockIsUpcoming = getBlockIsUpcoming(block); + if (blockIsUpcoming) { + await insert( + connection, + 'block_is_upcoming', + ['id', 'block_id'], + [block_is_upcoming_id++, block_id] + ); + } + const superblockId = superblock_to_superblock_id_map.get(superBlock); await insert( connection, diff --git a/dolt/queries/create-tables.sql b/dolt/queries/create-tables.sql index 171e14a4960a39..6c890e138184aa 100644 --- a/dolt/queries/create-tables.sql +++ b/dolt/queries/create-tables.sql @@ -73,6 +73,14 @@ CREATE TABLE IF NOT EXISTS block_time_to_complete( ) + CREATE TABLE IF NOT EXISTS block_is_upcoming( + id INT NOT NULL AUTO_INCREMENT, + block_id INT NOT NULL, + PRIMARY KEY (id), + FOREIGN KEY (block_id) REFERENCES blocks(id) + ) + + CREATE TABLE IF NOT EXISTS app_url( id INT AUTO_INCREMENT, challenge_id INT NOT NULL, diff --git a/dolt/queries/drop-tables.sql b/dolt/queries/drop-tables.sql index c552173fe5be98..07ae6f917eb6d9 100644 --- a/dolt/queries/drop-tables.sql +++ b/dolt/queries/drop-tables.sql @@ -2,6 +2,7 @@ DROP TABLE IF EXISTS app_url; DROP TABLE IF EXISTS assignments; DROP TABLE IF EXISTS audio_path; DROP TABLE IF EXISTS bilibili_ids; +DROP TABLE IF EXISTS block_is_upcoming; DROP TABLE IF EXISTS block_time_to_complete; DROP TABLE IF EXISTS blocks_challenges; DROP TABLE IF EXISTS certifications_prerequisites;