Skip to content

Commit 472dcfb

Browse files
committed
[FEATURE]: migrate users
1 parent 0092a6e commit 472dcfb

File tree

8 files changed

+310
-52
lines changed

8 files changed

+310
-52
lines changed

.env

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
NODE_ENV=test
2+
PORT=3000
3+
DB_HOST=127.0.0.1
4+
DB_PORT=27017
5+
DB_USER=behzad
6+
DB_PASSWORD=pass
7+
DB_NAME=TC-Community
8+
DISCORD_AUTHORIZE_CALLBACK_URI=http://localhost:3000/api/v1/auth/discord/authorize/callback
9+
DISCORD_CONNECT_CALLBACK_URI=http://localhost:3000/api/v1/platforms/discord/callback
10+
DISCROD_CLIENT_ID=1130918826234617968
11+
DISCORD_CLIENT_SECRET=6VvMOixzube7kBnIDBuMfTMym2-3bUBV
12+
DISCORD_BOT_TOKEN=MTEzMDkxODgyNjIzNDYxNzk2OA.GV79ch.bxToq-UkRQ9vwEmeESZKmm_BFp3DiggYachMzI
13+
TWITTER_CONNECT_CALLBACK_URI=http://localhost:3000/api/v1/platforms/twitter/callback
14+
TWITTER_CLIENT_ID=Q01ZSzFPaFVSVVlSRG5lTVpHeXE6MTpjaQ
15+
TWITTER_CLIENT_SECRET=N_gzHCLfQ_VubHMljLuBbckQ8hDclMyzPgkQT4DYjbA3M8UoRM
16+
JWT_SECRET=0%55e*enm@@u7v9+amg-ju_d_l6(v*88h4$#h&o-i7a4%tv*hx
17+
JWT_ACCESS_EXPIRATION_MINUTES=30
18+
JWT_REFRESH_EXPIRATION_DAYS=30
19+
JWT_DISCORD_REFRESH_EXPIRATION_DAY=30
20+
FRONTEND_URL=https://localhost:3000/login
21+
NOTION_API_KEY=secret_INw8tqjWs80yXTOndXrpfp44HxLAvpMzGNkQ2XxkvqM
22+
NOTION_DATABASE_ID=948a3d77051f4f9b848319819d776709
23+
RABBIT_HOST=localhost
24+
RABBIT_PORT=5672
25+
RABBIT_USER=guest
26+
RABBIT_PASSWORD=guest
27+
SENTRY_DSN=https://791ed14c7dc84377a291ba2dd60270bb@o4505110094282752.ingest.sentry.io/4505158976733184
28+
SENTRY_ENV=development
29+
NEO4J_PROTOCOL=bolt
30+
NEO4J_HOST=localhost
31+
NEO4J_PORT=7687
32+
NEO4J_USER=neo4j
33+
NEO4J_PASSWORD=neo4j1234
34+
NEO4J_DB=neo4j
35+
LOG_LEVEL=trace
36+
SESSION_SECRET=0%55e*enm@@u7v9+att-ju_d_l6(v*88h4$#h&o-i7a4%tv*yy
File renamed without changes.

.migrate

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"lastRun": "1702287534517-migrate-to-cc.ts",
3+
"migrations": [
4+
{
5+
"title": "1702287534517-migrate-to-cc.ts",
6+
"timestamp": 1702302181573
7+
}
8+
]
9+
}

package-lock.json

Lines changed: 70 additions & 42 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
"copy-files": "copyfiles -u 1 src/**/*.yml lib",
1111
"dev": "env-cmd -f ./src/config/dev.env nodemon ./src/index.ts",
1212
"test": "env-cmd -f ./src/config/test.env jest --detectOpenHandles",
13-
"migrate:create": "migrate create --template-file ./src/migrations/utils/template.ts --migrations-dir=\"./src/migrations/db\"",
14-
"migrate:up": "migrate --migrations-dir=\"./lib/migrations/db\" up",
15-
"migrate:down": "migrate --migrations-dir=\"./lib/migrations/db\" down"
13+
"migrate:create": "migrate create --template-file ./src/migrations/utils/template.ts --migrations-dir=\"./src/migrations/db\" --compiler=\"ts:./src/migrations/utils/ts-compiler.js\"",
14+
"migrate:up": "migrate --migrations-dir=\"./src/migrations/db\" up --compiler=\"ts:./src/migrations/utils/ts-compiler.js\"",
15+
"migrate:down": "migrate --migrations-dir=\"./src/migrations/db\" --compiler=\"ts:./src/migrations/utils/ts-compiler.js\" down"
1616
},
1717
"author": "",
1818
"license": "ISC",
@@ -70,14 +70,15 @@
7070
"@types/validator": "^13.7.10",
7171
"@typescript-eslint/eslint-plugin": "^5.45.0",
7272
"@typescript-eslint/parser": "^5.45.0",
73+
"dotenv": "^16.3.1",
7374
"env-cmd": "^10.1.0",
7475
"eslint": "^8.28.0",
7576
"jest": "^29.3.1",
7677
"node-mocks-http": "^1.12.1",
77-
"nodemon": "^2.0.20",
78+
"nodemon": "^3.0.2",
7879
"supertest": "^6.3.1",
7980
"ts-jest": "^29.0.3",
8081
"ts-node": "^10.9.1",
8182
"typescript": "^4.9.3"
8283
}
83-
}
84+
}

src/migrations/db/1702286459188-migrate-to-cc.ts renamed to src/migrations/db/1702287534517-migrate-to-cc.ts

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,45 @@
1+
import 'dotenv/config';
12
import mongoose from "mongoose";
23
import config from '../../config';
34
import logger from '../../config/logger';
4-
import 'dotenv/config';
5+
import { IUser, User } from '@togethercrew.dev/db'
56
import { DatabaseManager } from '@togethercrew.dev/db';
6-
import { User } from "@togethercrew.dev/db";
7+
import { IOldUser, IGuild, oldUserSchema, guildSchema } from '../utils/oldSchemas'
78

89
const connectToMongoDB = async () => {
910
try {
1011
await mongoose.connect(config.mongoose.serverURL);
12+
1113
logger.info({ url: config.mongoose.serverURL }, 'Connected to MongoDB!');
1214
} catch (error) {
1315
logger.fatal({ url: config.mongoose.serverURL, error }, 'Failed to connect to MongoDB!')
1416
}
1517
};
1618

19+
20+
21+
22+
1723
export const up = async () => {
1824
// Connect to MongoDB
1925
await connectToMongoDB();
26+
// const connection = mongoose.connection.useDb("RnDAO", { useCache: true });
2027
const connection = DatabaseManager.getInstance().getTenantDb("RnDAO");
21-
console.log(await connection.models.Guild.find({}));
28+
connection.model<IOldUser>('User', oldUserSchema);
29+
connection.model<IGuild>('Guild', guildSchema);
30+
2231

23-
console.log(await User.find({}))
32+
33+
const oldUsers = await connection.models.User.find({});
34+
const newUsers: IUser[] = [];
35+
for (let i = 0; i < oldUsers.length; i++) {
36+
newUsers.push({
37+
discordId: oldUsers[i].discordId,
38+
communities: [],
39+
tcaAt: oldUsers[i].createAt
40+
})
41+
}
42+
await User.create(newUsers)
2443
};
2544

2645
export const down = async () => {

0 commit comments

Comments
 (0)