rebrand - and parameterization
parent
71a203dd53
commit
c81f19e700
|
|
@ -1,10 +1,10 @@
|
||||||
{
|
{
|
||||||
"name": "viscord",
|
"name": "corner",
|
||||||
"lockfileVersion": 2,
|
"lockfileVersion": 2,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "viscord",
|
"name": "corner",
|
||||||
"hasInstallScript": true,
|
"hasInstallScript": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@types/mysql": "^2.15.21",
|
"@types/mysql": "^2.15.21",
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
{
|
{
|
||||||
"name": "viscord",
|
"name": "corner",
|
||||||
"description": "Secure boilerplate for Electron app based on Vite",
|
"description": "Secure boilerplate for Electron app based on Vite",
|
||||||
"private": true,
|
"private": true,
|
||||||
"engines": {
|
"engines": {
|
||||||
|
|
|
||||||
|
|
@ -41,6 +41,7 @@ const mockMessages: Message[] = [
|
||||||
|
|
||||||
export default () => {
|
export default () => {
|
||||||
const [messages, setMessages] = useState<Message[]>(mockMessages);
|
const [messages, setMessages] = useState<Message[]>(mockMessages);
|
||||||
|
const [hist, setHist] = useState(false);
|
||||||
|
|
||||||
const textBoxRef = useRef<HTMLDivElement>(null);
|
const textBoxRef = useRef<HTMLDivElement>(null);
|
||||||
|
|
||||||
|
|
@ -50,7 +51,7 @@ export default () => {
|
||||||
setMessages([...messages, data]);
|
setMessages([...messages, data]);
|
||||||
},
|
},
|
||||||
recent(data: { messages: Message[] }) {
|
recent(data: { messages: Message[] }) {
|
||||||
setMessages(data.messages);
|
setMessages([...data.messages, ...messages]);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
registerRouter(actions);
|
registerRouter(actions);
|
||||||
|
|
@ -60,11 +61,12 @@ export default () => {
|
||||||
}, [messages]);
|
}, [messages]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if(messages.length === 0) {
|
if(!hist) {
|
||||||
console.log('sending recents request');
|
console.log('sending recents request');
|
||||||
send('recent');
|
send('recent');
|
||||||
|
setHist(true);
|
||||||
}
|
}
|
||||||
}, [messages]);
|
}, [hist]);
|
||||||
|
|
||||||
const sendMessage = useCallback(() => {
|
const sendMessage = useCallback(() => {
|
||||||
if(textBoxRef.current === null) return;
|
if(textBoxRef.current === null) return;
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
DB_HOST=localhost
|
DB_HOST=localhost
|
||||||
DB_USER=root
|
DB_USER=root
|
||||||
DB_PASSWORD=example
|
DB_PASSWORD=example
|
||||||
DB_DB=viscord
|
DB_DB=corner
|
||||||
|
|
@ -1,12 +1,9 @@
|
||||||
SET NAMES utf8;
|
-- SET NAMES utf8;
|
||||||
SET time_zone = '+00:00';
|
-- SET time_zone = '+00:00';
|
||||||
SET foreign_key_checks = 0;
|
-- SET foreign_key_checks = 0;
|
||||||
SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO';
|
-- SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO';
|
||||||
|
|
||||||
SET NAMES utf8mb4;
|
-- SET NAMES utf8mb4;
|
||||||
|
|
||||||
CREATE DATABASE `viscord` /*!40100 DEFAULT CHARACTER SET utf8mb4 */;
|
|
||||||
USE `viscord`;
|
|
||||||
|
|
||||||
CREATE TABLE `messages` (
|
CREATE TABLE `messages` (
|
||||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||||
|
|
@ -21,7 +18,4 @@ CREATE TABLE `migrations` (
|
||||||
PRIMARY KEY (`id`)
|
PRIMARY KEY (`id`)
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||||
|
|
||||||
INSERT INTO `migrations` ()
|
|
||||||
VALUES ();
|
|
||||||
|
|
||||||
-- 2022-07-21 01:27:49
|
-- 2022-07-21 01:27:49
|
||||||
|
|
@ -1,8 +1,2 @@
|
||||||
|
|
||||||
USE `viscord`;
|
|
||||||
|
|
||||||
ALTER TABLE `messages`
|
ALTER TABLE `messages`
|
||||||
ADD COLUMN `t_sent` BIGINT UNSIGNED AFTER `text`;
|
ADD COLUMN `t_sent` BIGINT UNSIGNED AFTER `text`;
|
||||||
|
|
||||||
INSERT INTO `migrations` ()
|
|
||||||
VALUES ();
|
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
|
||||||
|
|
||||||
|
export const DB_HOST = 'localhost';
|
||||||
|
export const DB_USER = 'root';
|
||||||
|
export const DB_PASSWORD = 'example';
|
||||||
|
export const DB_NAME = 'corner';
|
||||||
|
|
@ -4,11 +4,13 @@ import { createConnection } from 'mysql';
|
||||||
import { readdirSync, readFileSync } from 'fs';
|
import { readdirSync, readFileSync } from 'fs';
|
||||||
import { dirname, resolve } from 'path';
|
import { dirname, resolve } from 'path';
|
||||||
import { fileURLToPath } from 'url';
|
import { fileURLToPath } from 'url';
|
||||||
|
import { DB_HOST, DB_NAME, DB_PASSWORD, DB_USER } from '../constants';
|
||||||
const __dirname = dirname(fileURLToPath(import.meta.url));
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||||
|
|
||||||
const host = 'localhost';
|
const host = DB_HOST;
|
||||||
const user = 'root';
|
const user = DB_USER;
|
||||||
const password = 'example';
|
const password = DB_PASSWORD;
|
||||||
|
const database = DB_NAME;
|
||||||
|
|
||||||
interface Migration {
|
interface Migration {
|
||||||
sql: string;
|
sql: string;
|
||||||
|
|
@ -35,6 +37,7 @@ export const connection = createConnection({
|
||||||
host,
|
host,
|
||||||
user,
|
user,
|
||||||
password,
|
password,
|
||||||
|
database,
|
||||||
});
|
});
|
||||||
const migrationConnection = createConnection({
|
const migrationConnection = createConnection({
|
||||||
host,
|
host,
|
||||||
|
|
@ -44,7 +47,7 @@ const migrationConnection = createConnection({
|
||||||
});
|
});
|
||||||
|
|
||||||
const connected: Promise<null> = new Promise((res, rej) => {
|
const connected: Promise<null> = new Promise((res, rej) => {
|
||||||
connection.connect((err) => {
|
migrationConnection.connect((err) => {
|
||||||
if(err === null) {
|
if(err === null) {
|
||||||
console.log('connected to database!');
|
console.log('connected to database!');
|
||||||
res(null);
|
res(null);
|
||||||
|
|
@ -61,17 +64,23 @@ export async function update() {
|
||||||
await connected;
|
await connected;
|
||||||
// determine version
|
// determine version
|
||||||
const currentVersion: number = await new Promise((resolve, rej) => {
|
const currentVersion: number = await new Promise((resolve, rej) => {
|
||||||
connection.query(`
|
migrationConnection.query(`
|
||||||
SELECT SCHEMA_NAME
|
SELECT SCHEMA_NAME
|
||||||
FROM INFORMATION_SCHEMA.SCHEMATA
|
FROM INFORMATION_SCHEMA.SCHEMATA
|
||||||
WHERE SCHEMA_NAME = 'viscord'
|
WHERE SCHEMA_NAME = '${database}';
|
||||||
`, async (err, res, fields) => {
|
`, async (err, res, fields) => {
|
||||||
if(res.length === 0) {
|
if(res.length === 0) {
|
||||||
|
await new Promise((resolve, reject) => {
|
||||||
|
migrationConnection.query(`CREATE DATABASE \`${database}\` /*!40100 DEFAULT CHARACTER SET utf8mb4 */;`, (err, res) => {
|
||||||
|
if(err) return reject(err);
|
||||||
|
return resolve(res);
|
||||||
|
});
|
||||||
|
});
|
||||||
resolve(0);
|
resolve(0);
|
||||||
} else {
|
} else {
|
||||||
const version: number = await new Promise((resolve, reject) => {
|
const version: number = await new Promise((resolve, reject) => {
|
||||||
connection.query(`
|
migrationConnection.query(`
|
||||||
SELECT max(id) as 'version' FROM viscord.migrations;
|
SELECT max(id) as 'version' FROM ${database}.migrations;
|
||||||
`, function (err, results, fields) {
|
`, function (err, results, fields) {
|
||||||
resolve(results[0].version);
|
resolve(results[0].version);
|
||||||
});
|
});
|
||||||
|
|
@ -87,17 +96,25 @@ export async function update() {
|
||||||
console.log('database up to date!');
|
console.log('database up to date!');
|
||||||
} else {
|
} else {
|
||||||
const difference = expectedVersion - currentVersion;
|
const difference = expectedVersion - currentVersion;
|
||||||
console.log(`database ${difference} version${difference !== 1 ? 's' : ''} behind`);
|
process.stdout.write(`database ${difference} version${difference !== 1 ? 's' : ''} behind`);
|
||||||
// console.log(`${currentVersion} >>> ${expectedVersion}`);
|
// console.log(`${currentVersion} >>> ${expectedVersion}`);
|
||||||
const neededMigrations = migrations.filter(m => m.version > currentVersion);
|
const neededMigrations = migrations.filter(m => m.version > currentVersion);
|
||||||
|
let completedMigrations = 0;
|
||||||
for(const migration of neededMigrations) {
|
for(const migration of neededMigrations) {
|
||||||
console.log(`${currentVersion} >>> ${migration.version}`);
|
console.log(`${currentVersion + completedMigrations} >>> ${migration.version}`);
|
||||||
await new Promise((resolve, reject) => {
|
await new Promise((resolve, reject) => {
|
||||||
migrationConnection.query(migration.sql, (err, res) => {
|
migrationConnection.query(`
|
||||||
|
USE \`${database}\`;
|
||||||
|
${migration.sql}
|
||||||
|
INSERT INTO \`migrations\` ()
|
||||||
|
VALUES ();
|
||||||
|
`, (err, res) => {
|
||||||
if(err !== null) return reject(err);
|
if(err !== null) return reject(err);
|
||||||
console.log(`executed ${res.length} statement${res.length !== 0 ? 's' : ''}`);
|
console.log(`executed ${res.length} statement${res.length !== 0 ? 's' : ''}`);
|
||||||
|
return resolve(void 0);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
completedMigrations ++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// console.log('database version:', currentVersion)
|
// console.log('database version:', currentVersion)
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
INSERT INTO viscord.messages
|
INSERT INTO messages
|
||||||
(`text`, `from`, `uid`, `t_sent`)
|
(`text`, `from`, `uid`, `t_sent`)
|
||||||
VALUES (
|
VALUES (
|
||||||
?,
|
?,
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,3 @@
|
||||||
SELECT * FROM viscord.messages
|
SELECT * FROM messages
|
||||||
ORDER BY t_sent
|
ORDER BY t_sent
|
||||||
LIMIT 100;
|
LIMIT 100;
|
||||||
|
|
@ -58,7 +58,7 @@ const setupServerPackageWatcher = () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
/** Proxy all logs */
|
/** Proxy all logs */
|
||||||
spawnProcess.stdout.on('data', d => d.toString().trim() && logger.info(d.toString().trim(), {timestamp: true}));
|
spawnProcess.stdout.on('data', d => d.toString().trim() && d.toString().trim().split('\n').forEach(str => logger.info(str, {timestamp: true})));
|
||||||
|
|
||||||
/** Proxy error logs but stripe some noisy messages. See {@link stderrFilterPatterns} */
|
/** Proxy error logs but stripe some noisy messages. See {@link stderrFilterPatterns} */
|
||||||
spawnProcess.stderr.on('data', d => {
|
spawnProcess.stderr.on('data', d => {
|
||||||
|
|
|
||||||
Reference in New Issue