39 lines
1.0 KiB
JavaScript
39 lines
1.0 KiB
JavaScript
import fs from 'node:fs/promises';
|
|
import path from 'node:path';
|
|
|
|
const root = path.resolve(import.meta.dirname, '..');
|
|
const schemaPath = path.join(root, 'database/schema.sql');
|
|
|
|
function tokens(line) {
|
|
return line
|
|
.trim()
|
|
.replaceAll(',', ' ')
|
|
.replaceAll(';', ' ')
|
|
.replaceAll('(', ' ')
|
|
.replaceAll(')', ' ')
|
|
.split(' ')
|
|
.map(token => token.trim())
|
|
.filter(Boolean);
|
|
}
|
|
|
|
function hasActivationColumn(schema) {
|
|
return schema
|
|
.split('\n')
|
|
.map(tokens)
|
|
.some(parts => {
|
|
const upper = parts.map(part => part.toUpperCase());
|
|
return upper[0] === 'ACTIVATED_AT'
|
|
&& upper[1] === 'TEXT'
|
|
&& upper.includes('DEFAULT')
|
|
&& upper.includes('NULL');
|
|
});
|
|
}
|
|
|
|
const schema = await fs.readFile(schemaPath, 'utf8');
|
|
|
|
if (!hasActivationColumn(schema)) {
|
|
throw new Error('database/schema.sql muss routes.activated_at als TEXT DEFAULT NULL enthalten.');
|
|
}
|
|
|
|
console.log('database/schema.sql enthält routes.activated_at als SQLite-STRICT-kompatible TEXT-Spalte.');
|