Skip to content

Commit d46f93f

Browse files
committed
migrations
1 parent e654559 commit d46f93f

13 files changed

+225
-1
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,4 @@ credentials/
6565

6666
public/
6767

68-
/src/database/migrations
68+
# /src/database/migrations
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// import { MigrationInterface, QueryRunner } from 'typeorm';
2+
3+
// export class PointIndex1729964897242 implements MigrationInterface {
4+
// public async up(queryRunner: QueryRunner): Promise<void> {
5+
// // 1. Add the 'location_point' column as NULLABLE
6+
// await queryRunner.query(`
7+
// ALTER TABLE wp_realty_listingsdb
8+
// ADD COLUMN location_point POINT NULL;
9+
// `);
10+
11+
// // 2. Populate the 'location_point' column with existing data
12+
// await queryRunner.query(`
13+
// UPDATE wp_realty_listingsdb
14+
// SET location_point = POINT(longitude, latitude);
15+
// `);
16+
17+
// // 3. Alter the 'location_point' column to NOT NULL
18+
// await queryRunner.query(`
19+
// ALTER TABLE wp_realty_listingsdb
20+
// MODIFY COLUMN location_point POINT NOT NULL;
21+
// `);
22+
23+
// // 4. Add a spatial index on the 'location_point' column
24+
// await queryRunner.query(`
25+
// ALTER TABLE wp_realty_listingsdb
26+
// ADD SPATIAL INDEX idx_location_point (location_point);
27+
// `);
28+
// }
29+
30+
// public async down(queryRunner: QueryRunner): Promise<void> {
31+
// // 1. Drop the spatial index
32+
// await queryRunner.query(`
33+
// ALTER TABLE wp_realty_listingsdb
34+
// DROP INDEX idx_location_point;
35+
// `);
36+
37+
// // 2. Drop the 'location_point' column
38+
// await queryRunner.query(`
39+
// ALTER TABLE wp_realty_listingsdb
40+
// DROP COLUMN location_point;
41+
// `);
42+
// }
43+
// }
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import { MigrationInterface, QueryRunner } from 'typeorm';
2+
3+
export class Init1731354031098 implements MigrationInterface {
4+
name = 'Init1731354031098';
5+
6+
public async up(queryRunner: QueryRunner): Promise<void> {
7+
await queryRunner.query(
8+
`CREATE TABLE \`otps\` (\`id\` int NOT NULL AUTO_INCREMENT, \`otp\` varchar(255) NOT NULL, \`otp_type\` varchar(255) NOT NULL, \`created_at\` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6), \`userId\` int NULL, PRIMARY KEY (\`id\`)) ENGINE=InnoDB`,
9+
);
10+
await queryRunner.query(
11+
`CREATE TABLE \`user_analytics\` (\`id\` int NOT NULL AUTO_INCREMENT, \`event_name\` enum ('page_view', 'property_view', 'property_like') NOT NULL, \`event\` varchar(255) NOT NULL, \`session\` varchar(40) NOT NULL, \`created_at\` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6), \`user_id\` int NULL, PRIMARY KEY (\`id\`)) ENGINE=InnoDB`,
12+
);
13+
await queryRunner.query(
14+
`CREATE TABLE \`users\` (\`created_at\` timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6), \`updated_at\` timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), \`deleted_at\` timestamp(6) NULL, \`id\` int NOT NULL AUTO_INCREMENT, \`email\` varchar(255) NOT NULL, \`first_name\` varchar(255) NOT NULL, \`last_name\` varchar(255) NOT NULL, \`profile_url\` varchar(255) NOT NULL DEFAULT 'https://cdn.pixabay.com/photo/2015/10/05/22/37/blank-profile-picture-973460_1280.png', \`password\` varchar(255) NULL, \`salt\` varchar(255) NULL, \`phone_number\` varchar(255) NULL, \`is_verified_email\` tinyint NOT NULL DEFAULT 0, \`role\` enum ('user', 'admin') NOT NULL DEFAULT 'user', UNIQUE INDEX \`IDX_97672ac88f789774dd47f7c8be\` (\`email\`), PRIMARY KEY (\`id\`)) ENGINE=InnoDB`,
15+
);
16+
await queryRunner.query(
17+
`CREATE TABLE \`top_entities\` (\`id\` int NOT NULL AUTO_INCREMENT, \`alias\` varchar(255) NOT NULL, \`entities\` json NULL, \`created_at\` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6), UNIQUE INDEX \`IDX_39e80e4855af2140fe606fc4cf\` (\`alias\`), PRIMARY KEY (\`id\`)) ENGINE=InnoDB`,
18+
);
19+
await queryRunner.query(
20+
`CREATE TABLE \`blogs\` (\`created_at\` timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6), \`updated_at\` timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), \`deleted_at\` timestamp(6) NULL, \`id\` varchar(36) NOT NULL, \`title\` varchar(100) NOT NULL, \`body\` varchar(1000) NOT NULL, \`thumbnail_url\` varchar(200) NOT NULL, \`tag\` varchar(20) NOT NULL, UNIQUE INDEX \`IDX_cf769f6545fecaa29c2f3a3c31\` (\`thumbnail_url\`), PRIMARY KEY (\`id\`)) ENGINE=InnoDB`,
21+
);
22+
await queryRunner.query(
23+
`ALTER TABLE \`otps\` ADD CONSTRAINT \`FK_82b0deb105275568cdcef2823eb\` FOREIGN KEY (\`userId\`) REFERENCES \`users\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`,
24+
);
25+
await queryRunner.query(
26+
`ALTER TABLE \`user_analytics\` ADD CONSTRAINT \`FK_1b21a2704e98eb4ad610a671f2a\` FOREIGN KEY (\`user_id\`) REFERENCES \`users\`(\`id\`) ON DELETE CASCADE ON UPDATE NO ACTION`,
27+
);
28+
}
29+
30+
public async down(queryRunner: QueryRunner): Promise<void> {
31+
await queryRunner.query(
32+
`ALTER TABLE \`user_analytics\` DROP FOREIGN KEY \`FK_1b21a2704e98eb4ad610a671f2a\``,
33+
);
34+
await queryRunner.query(
35+
`ALTER TABLE \`otps\` DROP FOREIGN KEY \`FK_82b0deb105275568cdcef2823eb\``,
36+
);
37+
await queryRunner.query(
38+
`DROP INDEX \`IDX_cf769f6545fecaa29c2f3a3c31\` ON \`blogs\``,
39+
);
40+
await queryRunner.query(`DROP TABLE \`blogs\``);
41+
await queryRunner.query(
42+
`DROP INDEX \`IDX_39e80e4855af2140fe606fc4cf\` ON \`top_entities\``,
43+
);
44+
await queryRunner.query(`DROP TABLE \`top_entities\``);
45+
await queryRunner.query(
46+
`DROP INDEX \`IDX_97672ac88f789774dd47f7c8be\` ON \`users\``,
47+
);
48+
await queryRunner.query(`DROP TABLE \`users\``);
49+
await queryRunner.query(`DROP TABLE \`user_analytics\``);
50+
await queryRunner.query(`DROP TABLE \`otps\``);
51+
}
52+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { MigrationInterface, QueryRunner } from 'typeorm';
2+
3+
export class AssociationSeed1731523167570 implements MigrationInterface {
4+
public async up(queryRunner: QueryRunner): Promise<void> {
5+
await queryRunner.query(`
6+
INSERT INTO top_entities (alias)
7+
VALUES ('top_builders'), ('top_associations'), ('top_cities')
8+
`);
9+
}
10+
11+
public async down(queryRunner: QueryRunner): Promise<void> {}
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { MigrationInterface, QueryRunner } from 'typeorm';
2+
3+
export class PropertyDeleted1731602767661 implements MigrationInterface {
4+
public async up(queryRunner: QueryRunner): Promise<void> {
5+
await queryRunner.query(`
6+
ALTER TABLE wp_realty_listingsdb
7+
ADD COLUMN is_active boolean NOT NULL DEFAULT true;
8+
`);
9+
}
10+
11+
public async down(queryRunner: QueryRunner): Promise<void> {}
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { MigrationInterface, QueryRunner } from 'typeorm';
2+
3+
export class TopEntitiesDefaults1733208998342 implements MigrationInterface {
4+
public async up(queryRunner: QueryRunner): Promise<void> {
5+
await queryRunner.query(`
6+
UPDATE top_entities
7+
set entities = '[]';
8+
`);
9+
}
10+
11+
public async down(queryRunner: QueryRunner): Promise<void> {}
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { MigrationInterface, QueryRunner } from 'typeorm';
2+
3+
export class TopEntitiesDefaults1733225239715 implements MigrationInterface {
4+
public async up(queryRunner: QueryRunner): Promise<void> {
5+
await queryRunner.query(`
6+
INSERT INTO top_entities (alias, entities)
7+
VALUES ('top_properties', '[]')
8+
`);
9+
}
10+
11+
public async down(queryRunner: QueryRunner): Promise<void> {}
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { MigrationInterface, QueryRunner } from 'typeorm';
2+
3+
export class AlterWpListing1733244531123 implements MigrationInterface {
4+
public async up(queryRunner: QueryRunner): Promise<void> {
5+
await queryRunner.query(`
6+
ALTER TABLE wp_realty_listingsdb
7+
ADD COLUMN property_images VARCHAR(255) NOT NULL DEFAULT '[]';
8+
`);
9+
}
10+
11+
public async down(queryRunner: QueryRunner): Promise<void> {}
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { MigrationInterface, QueryRunner } from 'typeorm';
2+
3+
export class AlterWpListing1733284879975 implements MigrationInterface {
4+
public async up(queryRunner: QueryRunner): Promise<void> {
5+
await queryRunner.query(`
6+
ALTER TABLE wp_realty_listingsdb
7+
MODIFY COLUMN property_images VARCHAR(5000) NOT NULL DEFAULT '[]';
8+
`);
9+
}
10+
11+
public async down(queryRunner: QueryRunner): Promise<void> {}
12+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { MigrationInterface, QueryRunner } from "typeorm";
2+
3+
export class Comment1733761676388 implements MigrationInterface {
4+
name = 'Comment1733761676388'
5+
6+
public async up(queryRunner: QueryRunner): Promise<void> {
7+
await queryRunner.query(`CREATE TABLE \`property_comment\` (\`created_at\` timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6), \`updated_at\` timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), \`deleted_at\` timestamp(6) NULL, \`id\` int NOT NULL AUTO_INCREMENT, \`comment\` varchar(255) NOT NULL, \`propertyId\` varchar(255) NOT NULL, \`name\` varchar(255) NOT NULL, \`email\` varchar(255) NOT NULL, PRIMARY KEY (\`id\`)) ENGINE=InnoDB`);
8+
}
9+
10+
public async down(queryRunner: QueryRunner): Promise<void> {
11+
await queryRunner.query(`DROP TABLE \`property_comment\``);
12+
}
13+
14+
}

0 commit comments

Comments
 (0)