anexado seed estado, municipio, parroquia y localidad en api
This commit is contained in:
8703
apps/api/src/database/seeds/default/Localities.ts
Normal file
8703
apps/api/src/database/seeds/default/Localities.ts
Normal file
File diff suppressed because it is too large
Load Diff
2087
apps/api/src/database/seeds/default/Municipalities.ts
Normal file
2087
apps/api/src/database/seeds/default/Municipalities.ts
Normal file
File diff suppressed because it is too large
Load Diff
6217
apps/api/src/database/seeds/default/Parishes.ts
Normal file
6217
apps/api/src/database/seeds/default/Parishes.ts
Normal file
File diff suppressed because it is too large
Load Diff
102
apps/api/src/database/seeds/default/States.ts
Normal file
102
apps/api/src/database/seeds/default/States.ts
Normal file
@@ -0,0 +1,102 @@
|
|||||||
|
export const States = [
|
||||||
|
{
|
||||||
|
id: 1,
|
||||||
|
name: "DTTO. CAPITAL",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 22,
|
||||||
|
name: "EDO. AMAZONAS",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 2,
|
||||||
|
name: "EDO. ANZOATEGUI",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 3,
|
||||||
|
name: "EDO. APURE",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 4,
|
||||||
|
name: "EDO. ARAGUA",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 5,
|
||||||
|
name: "EDO. BARINAS",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 6,
|
||||||
|
name: "EDO. BOLIVAR",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 7,
|
||||||
|
name: "EDO. CARABOBO",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 8,
|
||||||
|
name: "EDO. COJEDES",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 23,
|
||||||
|
name: "EDO. DELTA AMAC",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 9,
|
||||||
|
name: "EDO. FALCON",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 10,
|
||||||
|
name: "EDO. GUARICO",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 24,
|
||||||
|
name: "EDO. LA GUAIRA",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 11,
|
||||||
|
name: "EDO. LARA",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 12,
|
||||||
|
name: "EDO. MERIDA",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 13,
|
||||||
|
name: "EDO. MIRANDA",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 14,
|
||||||
|
name: "EDO. MONAGAS",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 15,
|
||||||
|
name: "EDO.NVA.ESPARTA",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 16,
|
||||||
|
name: "EDO. PORTUGUESA",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 17,
|
||||||
|
name: "EDO. SUCRE",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 18,
|
||||||
|
name: "EDO. TACHIRA",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 19,
|
||||||
|
name: "EDO. TRUJILLO",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 20,
|
||||||
|
name: "EDO. YARACUY",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 21,
|
||||||
|
name: "EDO. ZULIA",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 99,
|
||||||
|
name: "EMBAJADA",
|
||||||
|
},
|
||||||
|
];
|
||||||
5
apps/api/src/database/seeds/default/index.ts
Normal file
5
apps/api/src/database/seeds/default/index.ts
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
export * from './Localities';
|
||||||
|
export * from './Municipalities';
|
||||||
|
export * from './Parishes';
|
||||||
|
export * from './States';
|
||||||
|
|
||||||
@@ -1,19 +1,17 @@
|
|||||||
import { drizzle } from 'drizzle-orm/node-postgres';
|
import { drizzle, NodePgDatabase } from 'drizzle-orm/node-postgres';
|
||||||
import { Pool } from 'pg';
|
import { Pool } from 'pg';
|
||||||
import { envs } from 'src/common/config/envs';
|
import { envs } from 'src/common/config/envs';
|
||||||
import * as schema from '../index';
|
import * as schema from '../index';
|
||||||
import { seedAdminRole } from './admin-role.seed';
|
import { seedAdminRole } from './admin-role.seed';
|
||||||
|
import { seedLocalities } from './localities';
|
||||||
|
import { seedParishes } from './parishes';
|
||||||
|
import { seedStates } from './states';
|
||||||
import { seedUserAdmin } from './user-admin.seed';
|
import { seedUserAdmin } from './user-admin.seed';
|
||||||
import { seedStates } from './states.seed';
|
|
||||||
import { seedMunicipalities } from './municipalities.seed';
|
|
||||||
import { seedParishes } from './parishes.seed';
|
|
||||||
|
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
const pool = new Pool({
|
const pool = new Pool({
|
||||||
connectionString: envs.dataBaseUrl,
|
connectionString: envs.dataBaseUrl,
|
||||||
ssl:
|
ssl: envs.node_env === 'production' ? { rejectUnauthorized: false } : false,
|
||||||
envs.node_env === 'production' ? { rejectUnauthorized: false } : false,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const db = drizzle(pool, { schema });
|
const db = drizzle(pool, { schema });
|
||||||
@@ -21,10 +19,11 @@ async function main() {
|
|||||||
try {
|
try {
|
||||||
// Run seeds in order
|
// Run seeds in order
|
||||||
await seedStates(db);
|
await seedStates(db);
|
||||||
await seedMunicipalities(db);
|
await seedMunicipalites(db);
|
||||||
await seedParishes(db);
|
await seedParishes(db);
|
||||||
|
await seedLocalities(db);
|
||||||
await seedAdminRole(db);
|
await seedAdminRole(db);
|
||||||
await seedUserAdmin(db)
|
await seedUserAdmin(db);
|
||||||
|
|
||||||
console.log('All seeds completed successfully');
|
console.log('All seeds completed successfully');
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -35,3 +34,8 @@ async function main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
main();
|
main();
|
||||||
|
function seedMunicipalites(
|
||||||
|
db: NodePgDatabase<typeof schema> & { $client: Pool },
|
||||||
|
) {
|
||||||
|
throw new Error('Function not implemented.');
|
||||||
|
}
|
||||||
|
|||||||
21
apps/api/src/database/seeds/localities.ts
Normal file
21
apps/api/src/database/seeds/localities.ts
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
import { NodePgDatabase } from 'drizzle-orm/node-postgres';
|
||||||
|
import * as schema from '../index';
|
||||||
|
import { localities } from '../index';
|
||||||
|
import { Localities } from './default';
|
||||||
|
|
||||||
|
export async function seedLocalities(db: NodePgDatabase<typeof schema>) {
|
||||||
|
|
||||||
|
for (const locality of Localities) {
|
||||||
|
const localityData = {
|
||||||
|
...locality,
|
||||||
|
createdById: 1,
|
||||||
|
updatedById: 1,
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
await db.insert(localities).values(localityData).onConflictDoNothing();
|
||||||
|
} catch (error) {
|
||||||
|
console.error(`Error creating locality '${locality.name}':`, error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
console.log('localities seeded successfully');
|
||||||
|
}
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
import { NodePgDatabase } from 'drizzle-orm/node-postgres';
|
|
||||||
import * as schema from '../index';
|
|
||||||
import { municipalities } from '../schema/general';
|
|
||||||
|
|
||||||
|
|
||||||
export async function seedMunicipalities(db: NodePgDatabase<typeof schema>) {
|
|
||||||
console.log('Seeding public municipalities...');
|
|
||||||
|
|
||||||
// Insert roles
|
|
||||||
const municipalitiesArray = [{name:'municipio1',stateId:1}, {name:'municipio2',stateId:1}, {name:'municipio3',stateId:2}];
|
|
||||||
|
|
||||||
for (const item of municipalitiesArray) {
|
|
||||||
try {
|
|
||||||
await db.insert(municipalities).values({
|
|
||||||
name: item.name,
|
|
||||||
stateId: item.stateId
|
|
||||||
}).onConflictDoNothing();
|
|
||||||
// console.log(`Municipality '${item}' created or already exists`);
|
|
||||||
} catch (error) {
|
|
||||||
console.error(`Error creating municipality '${item.name}':`, error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log('All municipalities seeded successfully');
|
|
||||||
}
|
|
||||||
21
apps/api/src/database/seeds/municipalities.ts
Normal file
21
apps/api/src/database/seeds/municipalities.ts
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
import { NodePgDatabase } from 'drizzle-orm/node-postgres';
|
||||||
|
import * as schema from '../index';
|
||||||
|
import { municipalities } from '../index';
|
||||||
|
import { Municipalities } from './default';
|
||||||
|
|
||||||
|
export async function seedMunicipalites(db: NodePgDatabase<typeof schema>) {
|
||||||
|
|
||||||
|
for (const municipality of Municipalities) {
|
||||||
|
const municipalityData = {
|
||||||
|
...municipality,
|
||||||
|
createdById: 1,
|
||||||
|
updatedById: 1,
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
await db.insert(municipalities).values(municipalityData).onConflictDoNothing();
|
||||||
|
} catch (error) {
|
||||||
|
console.error(`Error creating municipality '${municipality.name}':`, error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
console.log('Municipalities seeded successfully');
|
||||||
|
}
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
import { NodePgDatabase } from 'drizzle-orm/node-postgres';
|
|
||||||
import * as schema from '../index';
|
|
||||||
import { parishes } from '../schema/general';
|
|
||||||
|
|
||||||
|
|
||||||
export async function seedParishes(db: NodePgDatabase<typeof schema>) {
|
|
||||||
console.log('Seeding public parishes...');
|
|
||||||
|
|
||||||
// Insert roles
|
|
||||||
const parishesArray = [{name:'parroquia1',municipalityId:1}, {name:'parroquia2',municipalityId:1}, {name:'parroquia3',municipalityId:2}];
|
|
||||||
|
|
||||||
for (const item of parishesArray) {
|
|
||||||
try {
|
|
||||||
await db.insert(parishes).values({
|
|
||||||
name: item.name,
|
|
||||||
municipalityId: item.municipalityId
|
|
||||||
}).onConflictDoNothing();
|
|
||||||
// console.log(`Parish '${item}' created or already exists`);
|
|
||||||
} catch (error) {
|
|
||||||
console.error(`Error creating parish '${item.name}':`, error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log('All parishes seeded successfully');
|
|
||||||
}
|
|
||||||
21
apps/api/src/database/seeds/parishes.ts
Normal file
21
apps/api/src/database/seeds/parishes.ts
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
import { NodePgDatabase } from 'drizzle-orm/node-postgres';
|
||||||
|
import * as schema from '../index';
|
||||||
|
import { parishes } from '../index';
|
||||||
|
import { Parishes } from './default';
|
||||||
|
|
||||||
|
export async function seedParishes(db: NodePgDatabase<typeof schema>) {
|
||||||
|
|
||||||
|
for (const parish of Parishes) {
|
||||||
|
const parishData = {
|
||||||
|
...parish,
|
||||||
|
createdById: 1,
|
||||||
|
updatedById: 1,
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
await db.insert(parishes).values(parishData).onConflictDoNothing();
|
||||||
|
} catch (error) {
|
||||||
|
console.error(`Error creating parihs '${parish.name}':`, error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
console.log('Parishes seeded successfully');
|
||||||
|
}
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
import { NodePgDatabase } from 'drizzle-orm/node-postgres';
|
|
||||||
import * as schema from '../index';
|
|
||||||
import { states } from '../schema/general';
|
|
||||||
|
|
||||||
|
|
||||||
export async function seedStates(db: NodePgDatabase<typeof schema>) {
|
|
||||||
console.log('Seeding public state...');
|
|
||||||
|
|
||||||
// Insert roles
|
|
||||||
const statesArray = ['estado1', 'estado2', 'estado3'];
|
|
||||||
|
|
||||||
for (const item of statesArray) {
|
|
||||||
try {
|
|
||||||
await db.insert(states).values({
|
|
||||||
name: item
|
|
||||||
}).onConflictDoNothing();
|
|
||||||
// console.log(`State '${item}' created or already exists`);
|
|
||||||
} catch (error) {
|
|
||||||
console.error(`Error creating state '${item}':`, error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log('All states seeded successfully');
|
|
||||||
}
|
|
||||||
21
apps/api/src/database/seeds/states.ts
Normal file
21
apps/api/src/database/seeds/states.ts
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
import { NodePgDatabase } from 'drizzle-orm/node-postgres';
|
||||||
|
import * as schema from '../index';
|
||||||
|
import { states } from '../index';
|
||||||
|
import { States } from './default';
|
||||||
|
|
||||||
|
export async function seedStates(db: NodePgDatabase<typeof schema>) {
|
||||||
|
|
||||||
|
for (const state of States) {
|
||||||
|
const stateData = {
|
||||||
|
...state,
|
||||||
|
createdById: 1,
|
||||||
|
updatedById: 1,
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
await db.insert(states).values(stateData).onConflictDoNothing();
|
||||||
|
} catch (error) {
|
||||||
|
console.error(`Error creating state '${state.name}':`, error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
console.log('State seeded successfully');
|
||||||
|
}
|
||||||
@@ -1,34 +1,41 @@
|
|||||||
import { NodePgDatabase } from 'drizzle-orm/node-postgres';
|
import { NodePgDatabase } from 'drizzle-orm/node-postgres';
|
||||||
import * as schema from '../index';
|
import * as schema from '../index';
|
||||||
import { users, usersRole } from '../index';
|
import { users, usersRole } from '../index';
|
||||||
|
|
||||||
export async function seedUserAdmin(db: NodePgDatabase<typeof schema>) {
|
export async function seedUserAdmin(db: NodePgDatabase<typeof schema>) {
|
||||||
|
|
||||||
// Insert admin user
|
// Insert admin user
|
||||||
try {
|
try {
|
||||||
// Password is already hashed in your SQL, but in a real application you might want to hash it here
|
// Password is already hashed in your SQL, but in a real application you might want to hash it here
|
||||||
// const hashedPassword = await hash('your_password', 10);
|
// const hashedPassword = await hash('your_password', 10);
|
||||||
const hashedPassword = '$2b$10$6esl7d/BOINamScuReRoPuYFC8iSJgpk61LHm2X3PCU5hu/St8vHW';
|
const hashedPassword =
|
||||||
|
'$2b$10$6esl7d/BOINamScuReRoPuYFC8iSJgpk61LHm2X3PCU5hu/St8vHW';
|
||||||
|
|
||||||
const [adminUser] = await db.insert(users).values({
|
const [adminUser] = await db
|
||||||
username: 'superadmin',
|
.insert(users)
|
||||||
email: 'admin@zonastart.com',
|
.values({
|
||||||
fullname: 'Super Administrador',
|
username: 'superadmin',
|
||||||
password: hashedPassword,
|
email: 'admin@fondemi.gob.ve',
|
||||||
state: 1,
|
fullname: 'Super Administrador',
|
||||||
municipality: 1,
|
password: hashedPassword,
|
||||||
parish: 1,
|
state: 1,
|
||||||
isTwoFactorEnabled: false,
|
municipality: 1,
|
||||||
isEmailVerified: true,
|
parish: 1,
|
||||||
isActive: true
|
isTwoFactorEnabled: false,
|
||||||
}).returning({ id: users.id }).onConflictDoNothing();
|
isEmailVerified: true,
|
||||||
|
isActive: true,
|
||||||
|
})
|
||||||
|
.returning({ id: users.id })
|
||||||
|
.onConflictDoNothing();
|
||||||
|
|
||||||
if (adminUser) {
|
if (adminUser) {
|
||||||
// Assign superadmin role to the user
|
// Assign superadmin role to the user
|
||||||
await db.insert(usersRole).values({
|
await db
|
||||||
roleId: 1, // Assuming 'superadmin' has ID 1 based on the insert order
|
.insert(usersRole)
|
||||||
userId: adminUser.id
|
.values({
|
||||||
}).onConflictDoNothing();
|
roleId: 1, // Assuming 'superadmin' has ID 1 based on the insert order
|
||||||
|
userId: adminUser.id,
|
||||||
|
})
|
||||||
|
.onConflictDoNothing();
|
||||||
console.log('Admin user created and assigned superadmin role');
|
console.log('Admin user created and assigned superadmin role');
|
||||||
} else {
|
} else {
|
||||||
console.log('Admin user already exists, skipping');
|
console.log('Admin user already exists, skipping');
|
||||||
@@ -36,4 +43,4 @@ export async function seedUserAdmin(db: NodePgDatabase<typeof schema>) {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error creating admin user:', error);
|
console.error('Error creating admin user:', error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user