mirror of
https://github.com/HangarMC/Hangar.git
synced 2024-11-21 01:21:54 +08:00
chore: nuke migrator
you served us well my friend
This commit is contained in:
parent
db4ab06bb6
commit
5d88237b0c
@ -1,94 +0,0 @@
|
||||
import pg from "pg";
|
||||
|
||||
const {Pool} = pg;
|
||||
|
||||
const kratosPool = new Pool({
|
||||
connectionString: "postgresql://hangarauth:@localhost:1234/hangarauth",
|
||||
ssl: {rejectUnauthorized: false}
|
||||
//connectionString: "postgresql://hangar:hangar@localhost:5432/kratos",
|
||||
});
|
||||
|
||||
const hangarPool = new Pool({
|
||||
connectionString: "postgresql://hangar:@localhost:1234/hangar",
|
||||
ssl: {rejectUnauthorized: false}
|
||||
//connectionString: "postgresql://hangar:hangar@localhost:5432/hangar",
|
||||
});
|
||||
|
||||
const res = await kratosPool.query(`
|
||||
SELECT i.id uuid,
|
||||
i.traits ->> 'username' username,
|
||||
iva.status email_verified,
|
||||
iva.value email,
|
||||
ic.config creds,
|
||||
ict.name cred_type,
|
||||
ic.created_at created_at,
|
||||
ic.updated_at updated_at,
|
||||
json_build_object('github', i.traits ->> 'github', 'discord', i.traits ->> 'discord') socials
|
||||
FROM identities i
|
||||
JOIN identity_verifiable_addresses iva ON i.id = iva.identity_id
|
||||
JOIN identity_credentials ic ON i.id = ic.identity_id
|
||||
JOIN identity_credential_types ict ON ict.id = ic.identity_credential_type_id
|
||||
ORDER BY username
|
||||
`);
|
||||
console.log("queried " + res.rows.length + " rows!");
|
||||
|
||||
for (let row of res.rows) {
|
||||
console.log("migrating " + row.username + " " + row.cred_type);
|
||||
|
||||
// first, check if user exists
|
||||
const user = await hangarPool.query(`
|
||||
SELECT id
|
||||
FROM users
|
||||
WHERE uuid = $1
|
||||
`, [row.uuid]);
|
||||
|
||||
let userId = user?.rows?.[0]?.id;
|
||||
if (!userId) {
|
||||
console.warn("Unknown user " + row.username + ", creating", user.rows);
|
||||
const verified = row.email_verified === "completed";
|
||||
const insert = await hangarPool.query(`
|
||||
INSERT INTO users(uuid, created_at, name, email, join_date, email_verified, socials)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7)
|
||||
RETURNING id
|
||||
`, [row.uuid, row.created_at, row.username, row.email, row.created_at, verified, row.socials]);
|
||||
userId = insert?.rows?.[0]?.id;
|
||||
if (!userId) {
|
||||
console.error("insert fucked?", row, insert);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
await hangarPool.query("BEGIN");
|
||||
|
||||
let type;
|
||||
if (row.cred_type === "password") {
|
||||
type = 0;
|
||||
} else if (row.cred_type === "lookup_secret") {
|
||||
type = 1;
|
||||
} else if (row.cred_type === "totp") {
|
||||
type = 2;
|
||||
} else if (row.cred_type === "webauthn") {
|
||||
type = 3;
|
||||
}
|
||||
|
||||
await hangarPool.query(`
|
||||
INSERT INTO user_credentials(created_at, user_id, credential, type, updated_at)
|
||||
VALUES ($1, $2, $3, $4, $5)
|
||||
ON CONFLICT (user_id, type) DO UPDATE SET created_at = $1, credential = $3, updated_at = $5
|
||||
`, [row.created_at, userId, row.creds, type, row.updated_at]);
|
||||
|
||||
const verified = row.email_verified === "completed";
|
||||
await hangarPool.query(`UPDATE users
|
||||
SET email_verified = $1, socials = $2
|
||||
WHERE id = $3`, [verified, row.socials, userId])
|
||||
|
||||
await hangarPool.query("COMMIT");
|
||||
} catch (e) {
|
||||
await hangarPool.query("ROLLBACK");
|
||||
console.error("Failed to migrate " + row.username + " " + row.cred_type);
|
||||
console.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
await kratosPool.end();
|
@ -1,15 +0,0 @@
|
||||
{
|
||||
"name": "dum",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"pg": "^8.10.0"
|
||||
}
|
||||
}
|
@ -1,106 +0,0 @@
|
||||
lockfileVersion: 5.4
|
||||
|
||||
specifiers:
|
||||
pg: ^8.10.0
|
||||
|
||||
dependencies:
|
||||
pg: 8.10.0
|
||||
|
||||
packages:
|
||||
|
||||
/buffer-writer/2.0.0:
|
||||
resolution: {integrity: sha512-a7ZpuTZU1TRtnwyCNW3I5dc0wWNC3VR9S++Ewyk2HHZdrO3CQJqSpd+95Us590V6AL7JqUAH2IwZ/398PmNFgw==}
|
||||
engines: {node: '>=4'}
|
||||
dev: false
|
||||
|
||||
/packet-reader/1.0.0:
|
||||
resolution: {integrity: sha512-HAKu/fG3HpHFO0AA8WE8q2g+gBJaZ9MG7fcKk+IJPLTGAD6Psw4443l+9DGRbOIh3/aXr7Phy0TjilYivJo5XQ==}
|
||||
dev: false
|
||||
|
||||
/pg-connection-string/2.5.0:
|
||||
resolution: {integrity: sha512-r5o/V/ORTA6TmUnyWZR9nCj1klXCO2CEKNRlVuJptZe85QuhFayC7WeMic7ndayT5IRIR0S0xFxFi2ousartlQ==}
|
||||
dev: false
|
||||
|
||||
/pg-int8/1.0.1:
|
||||
resolution: {integrity: sha512-WCtabS6t3c8SkpDBUlb1kjOs7l66xsGdKpIPZsg4wR+B3+u9UAum2odSsF9tnvxg80h4ZxLWMy4pRjOsFIqQpw==}
|
||||
engines: {node: '>=4.0.0'}
|
||||
dev: false
|
||||
|
||||
/pg-pool/3.6.0_pg@8.10.0:
|
||||
resolution: {integrity: sha512-clFRf2ksqd+F497kWFyM21tMjeikn60oGDmqMT8UBrynEwVEX/5R5xd2sdvdo1cZCFlguORNpVuqxIj+aK4cfQ==}
|
||||
peerDependencies:
|
||||
pg: '>=8.0'
|
||||
dependencies:
|
||||
pg: 8.10.0
|
||||
dev: false
|
||||
|
||||
/pg-protocol/1.6.0:
|
||||
resolution: {integrity: sha512-M+PDm637OY5WM307051+bsDia5Xej6d9IR4GwJse1qA1DIhiKlksvrneZOYQq42OM+spubpcNYEo2FcKQrDk+Q==}
|
||||
dev: false
|
||||
|
||||
/pg-types/2.2.0:
|
||||
resolution: {integrity: sha512-qTAAlrEsl8s4OiEQY69wDvcMIdQN6wdz5ojQiOy6YRMuynxenON0O5oCpJI6lshc6scgAY8qvJ2On/p+CXY0GA==}
|
||||
engines: {node: '>=4'}
|
||||
dependencies:
|
||||
pg-int8: 1.0.1
|
||||
postgres-array: 2.0.0
|
||||
postgres-bytea: 1.0.0
|
||||
postgres-date: 1.0.7
|
||||
postgres-interval: 1.2.0
|
||||
dev: false
|
||||
|
||||
/pg/8.10.0:
|
||||
resolution: {integrity: sha512-ke7o7qSTMb47iwzOSaZMfeR7xToFdkE71ifIipOAAaLIM0DYzfOAXlgFFmYUIE2BcJtvnVlGCID84ZzCegE8CQ==}
|
||||
engines: {node: '>= 8.0.0'}
|
||||
peerDependencies:
|
||||
pg-native: '>=3.0.1'
|
||||
peerDependenciesMeta:
|
||||
pg-native:
|
||||
optional: true
|
||||
dependencies:
|
||||
buffer-writer: 2.0.0
|
||||
packet-reader: 1.0.0
|
||||
pg-connection-string: 2.5.0
|
||||
pg-pool: 3.6.0_pg@8.10.0
|
||||
pg-protocol: 1.6.0
|
||||
pg-types: 2.2.0
|
||||
pgpass: 1.0.5
|
||||
dev: false
|
||||
|
||||
/pgpass/1.0.5:
|
||||
resolution: {integrity: sha512-FdW9r/jQZhSeohs1Z3sI1yxFQNFvMcnmfuj4WBMUTxOrAyLMaTcE1aAMBiTlbMNaXvBCQuVi0R7hd8udDSP7ug==}
|
||||
dependencies:
|
||||
split2: 4.2.0
|
||||
dev: false
|
||||
|
||||
/postgres-array/2.0.0:
|
||||
resolution: {integrity: sha512-VpZrUqU5A69eQyW2c5CA1jtLecCsN2U/bD6VilrFDWq5+5UIEVO7nazS3TEcHf1zuPYO/sqGvUvW62g86RXZuA==}
|
||||
engines: {node: '>=4'}
|
||||
dev: false
|
||||
|
||||
/postgres-bytea/1.0.0:
|
||||
resolution: {integrity: sha512-xy3pmLuQqRBZBXDULy7KbaitYqLcmxigw14Q5sj8QBVLqEwXfeybIKVWiqAXTlcvdvb0+xkOtDbfQMOf4lST1w==}
|
||||
engines: {node: '>=0.10.0'}
|
||||
dev: false
|
||||
|
||||
/postgres-date/1.0.7:
|
||||
resolution: {integrity: sha512-suDmjLVQg78nMK2UZ454hAG+OAW+HQPZ6n++TNDUX+L0+uUlLywnoxJKDou51Zm+zTCjrCl0Nq6J9C5hP9vK/Q==}
|
||||
engines: {node: '>=0.10.0'}
|
||||
dev: false
|
||||
|
||||
/postgres-interval/1.2.0:
|
||||
resolution: {integrity: sha512-9ZhXKM/rw350N1ovuWHbGxnGh/SNJ4cnxHiM0rxE4VN41wsg8P8zWn9hv/buK00RP4WvlOyr/RBDiptyxVbkZQ==}
|
||||
engines: {node: '>=0.10.0'}
|
||||
dependencies:
|
||||
xtend: 4.0.2
|
||||
dev: false
|
||||
|
||||
/split2/4.2.0:
|
||||
resolution: {integrity: sha512-UcjcJOWknrNkF6PLX83qcHM6KHgVKNkV62Y8a5uYDVv9ydGQVwAHMKqHdJje1VTWpljG0WYpCDhrCdAOYH4TWg==}
|
||||
engines: {node: '>= 10.x'}
|
||||
dev: false
|
||||
|
||||
/xtend/4.0.2:
|
||||
resolution: {integrity: sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ==}
|
||||
engines: {node: '>=0.4'}
|
||||
dev: false
|
Loading…
Reference in New Issue
Block a user