Initial project source

这个提交包含在:
apple
2026-11-20 15:32:57 +08:00
当前提交 fb47c07f7c
共修改 8405 个文件,包含 806907 行新增和 0 行删除
+73
查看文件
@@ -0,0 +1,73 @@
#!/usr/bin/env python3
"""Assemble reviewed schema, safe seeds and allowlisted exported data for a fresh install."""
import base64
import hashlib
import importlib.util
import json
from pathlib import Path
import shutil
import zipfile
ROOT = Path(__file__).resolve().parents[2]
OUT = ROOT / 'release/dameng-20261118'
spec = importlib.util.spec_from_file_location('seed', ROOT / 'script/database/apply-dameng-seed.py')
seed = importlib.util.module_from_spec(spec)
spec.loader.exec_module(seed)
data = json.loads((ROOT / 'db/dameng/seed.json').read_text())
source = OUT / 'database/library-data.sql'
counts, samples, longest = {}, {}, {}
buffer = ''
for line in source.open():
if not buffer and line.startswith('-- '):
name, count = line[3:].strip().split(' rows=')
assert counts.get(name, 0) == int(count), name
counts[name] = int(count)
continue
buffer += line
if buffer.count("'") % 2 or not buffer.rstrip().endswith(';'):
continue
table = buffer.split('(', 1)[0].split()[-1]
counts[table] = counts.get(table, 0) + 1
samples.setdefault(table, buffer.rstrip().removesuffix(';'))
if len(buffer) > len(longest.get(table, '')):
longest[table] = buffer.rstrip().removesuffix(';')
buffer = ''
assert not buffer
sql = OUT / 'database/aixun-datagov-init.sql'
with sql.open('w') as out:
out.write('-- DM8 fresh install only. Execute as SYSDBA; stop on any error. UTF-8.\n')
out.write('-- Never run on an existing schema. Configure application DM_SCHEMA=AIXUN_DATAGOV_PROD.\n')
out.write('CREATE SCHEMA AIXUN_DATAGOV_PROD AUTHORIZATION SYSDBA;\nSET SCHEMA AIXUN_DATAGOV_PROD;\n')
out.write((ROOT / 'db/dameng/schema.sql').read_text())
out.write('\n-- Built-in initialization data; accounts disabled until password configured.\n')
for table, values in data.items():
if table in counts:
continue
counts[table] = len(values['rows'])
for row in values['rows']:
statement = 'INSERT INTO '+table+'('+','.join(values['columns'])+') VALUES('+','.join(map(seed.literal,row))+')'
out.write(statement+';\n')
samples.setdefault(table, statement)
with source.open() as incoming:
shutil.copyfileobj(incoming, out)
out.write('\nCOMMIT;\n-- Expected row counts for post-install verification:\n')
for table,count in counts.items():
out.write(f"SELECT '{table}' AS TABLE_NAME, COUNT(*) AS ACTUAL_ROWS, {count} AS EXPECTED_ROWS FROM {table};\n")
(OUT / 'database/row-counts.json').write_text(json.dumps(counts, indent=2)+'\n')
with (OUT / 'database/prepare-samples.txt').open('w') as out:
for name, statement in list(samples.items())+[(k+'_longest',v) for k,v in longest.items()]:
out.write(name+'\t'+base64.b64encode(statement.encode()).decode()+'\n')
backend = OUT / 'backend'
backend.mkdir(exist_ok=True)
jars=[]
for base in ['aixun-auth','aixun-gateway','aixun-modules','aixun-common','aixun-api']:
for jar in sorted((ROOT/base).glob('**/target/*.jar')):
with zipfile.ZipFile(jar) as archive:
executable='BOOT-INF/classes/' in archive.namelist()
target=backend / ('services' if executable else 'libraries') / jar.name
target.parent.mkdir(exist_ok=True)
shutil.copy2(jar,target)
jars.append({'file':str(target.relative_to(OUT)),'source':str(jar.relative_to(ROOT)),'executable':executable})
(OUT/'backend/jars.json').write_text(json.dumps(jars,indent=2)+'\n')
shutil.copytree(ROOT/'aixun-ui/dist', OUT/'frontend/dist', dirs_exist_ok=True)
print('TABLES_WITH_DATA',len(counts),'ROWS',sum(counts.values()),'JARS',len(jars),'SERVICES',sum(j['executable'] for j in jars))