diff --git a/docker-compose.yml b/docker-compose.yml index 98113da7176558f9aade7396bbefdcdb921bc9a7..366c210df22844cb8e690352869b9418a6b5f917 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -3,9 +3,9 @@ services: image: postgres restart: always environment: - POSTGRES_DB: apex_db - POSTGRES_USER: postgres - POSTGRES_PASSWORD: postgres + POSTGRES_DB: mecred_test + POSTGRES_USER: mecred + POSTGRES_PASSWORD: 123mudar ports: - "5432:5432" networks: diff --git a/src/db/schema/achievements.ts b/src/db/schema/achievements.ts new file mode 100644 index 0000000000000000000000000000000000000000..66269d25dc36c710476ac4d6b29e06795c388e43 --- /dev/null +++ b/src/db/schema/achievements.ts @@ -0,0 +1,162 @@ +// colocar os id depois de tudo pronto, no momento +// ta tudo igual ao passado + + + +import { bigint } from 'drizzle-orm/pg-core' +import { + pgTable, + boolean, + timestamp, + integer, + text, + varchar, + } from 'drizzle-orm/pg-core' + + + export const achievements = pgTable('achievements', { + id: bigint('id', {mode: 'number'}).primaryKey().notNull(), + name: varchar('name', { length: 255}), + description: text('description'), + rewardExperience: integer('reward_experience'), + rewardPoints: integer('reward_points'), + state: integer('state'), + repeatable: integer('repeatable'), + resettable: boolean('resettable'), + createdAt: timestamp('created_at', { withTimezone: false }).notNull(), + updatedAt: timestamp('updated_at', { withTimezone: false }).notNull(), +}); + +export const achievementsRequirements = pgTable('achievements_requirements', { + achievementId: bigint('achievement_id', {mode: 'number'}).notNull(), + requirementId: bigint('requirement_id', {mode: 'number'}).notNull(), + createdAt: timestamp('created_at', { withTimezone: false }).notNull(), + updatedAt: timestamp('updated_at', { withTimezone: false }).notNull(), +}); + + +export const actionCounters = pgTable('action_counters', { + id: bigint('id', {mode: 'number'}).primaryKey().notNull(), + userId: bigint('user_id', {mode: 'number'}).unique(), + actionId: bigint('action_id', {mode: 'number'}).unique(), + counter: integer('counter').default(0), + createdAt: timestamp('created_at', { withTimezone: false }).notNull(), + updatedAt: timestamp('updated_at', { withTimezone: false }).notNull(), +}); + +export const actions = pgTable('actions', { + id: bigint('id', {mode: 'number'}).primaryKey().notNull(), + name: varchar('name', {length: 255}), + description: text('description'), + rewardExperience: integer('reward_experience'), + createdAt: timestamp('created_at', { withTimezone: false }).notNull(), + updatedAt: timestamp('updated_at', { withTimezone: false }).notNull(), +}); + +export const activities = pgTable('activities', { + id: integer('id').primaryKey().notNull(), + trackableType: varchar('trackable_type', {length: 255}), + trackableId: integer('trackable_id'), + ownerType: varchar('owner_type', {length: 255}), + ownerId: integer('owner_id'), + key: varchar('key', {length: 255}), + parameters: text('parameters'), + recipientType: varchar('recipient_type', {length: 255}), + recipientId: integer('recipient_id'), + createdAt: timestamp('created_at', { withTimezone: false }).notNull(), + updatedAt: timestamp('updated_at', { withTimezone: false }).notNull(), + privacy: varchar('privacy', {length: 255}), + viewsCount: integer('views_count'), +}); + + +export const answers = pgTable('answers', { + id: integer('id').primaryKey().notNull(), + questionId: integer('question_id'), + submissionId: integer('submission_id'), + accepted: boolean('accepted'), + createdAt: timestamp('created_at', { withTimezone: false }).notNull(), + updatedAt: timestamp('updated_at', { withTimezone: false }).notNull(), +}); + +export const applications = pgTable('applications', { + id: integer('id').primaryKey().notNull(), + name: varchar('name', { length: 255 }), + domain: varchar('domain', { length: 255 }).unique(), + applicationId: varchar('application_id', { length: 255 }).unique(), + userId: integer('user_id'), + createdAt: timestamp('created_at', { withTimezone: false }).notNull(), + updatedAt: timestamp('updated_at', { withTimezone: false }).notNull(), +}); + +export const arInternalMetadata = pgTable('ar_internal_metadata', { + key: varchar('key', { length: 255 }).primaryKey().notNull(), + value: varchar('value', { length: 255 }), + createdAt: timestamp('created_at', { withTimezone: false }).notNull(), + updatedAt: timestamp('updated_at', { withTimezone: false }).notNull(), +}); + +export const bookmarks = pgTable('bookmarks', { + id: integer('id').primaryKey().notNull(), + userId: integer('user_id').unique(), + bookmarkableType: varchar('bookmarkable_type', { length: 255 }).unique(), + bookmarkableId: integer('bookmarkable_id').unique(), + createdAt: timestamp('created_at', { withTimezone: false }).notNull(), + updatedAt: timestamp('updated_at', { withTimezone: false }).notNull(), +}); + +export const carousels = pgTable('carousels', { + id: integer('id').primaryKey().notNull(), + title: varchar('title', { length: 255 }), + url: text('url'), + createdAt: timestamp('created_at', { withTimezone: false }).notNull(), + updatedAt: timestamp('updated_at', { withTimezone: false }).notNull(), + imageFileName: varchar('image_file_name', { length: 255 }), + imageContentType: varchar('image_content_type', { length: 255 }), + imageFileSize: integer('image_file_size'), + imageUpdatedAt: timestamp('image_updated_at', { withTimezone: false }), +}); + +export const progresses = pgTable('progresses', { + id: bigint('id', {mode: 'number'}).primaryKey().notNull(), + userId: bigint('user_id', {mode: 'number'}).unique(), + requirementId: bigint('requirement_id', {mode: 'number'}).unique(), + counter: integer('counter').default(0), + createdAt: timestamp('created_at', { withTimezone: false }).notNull(), + updatedAt: timestamp('updated_at', { withTimezone: false }).notNull(), +}); + +export const questions = pgTable('questions', { + id: integer('id').primaryKey().notNull(), + description: varchar('description', { length: 255}), + status: integer('status').default(0), + createdAt: timestamp('created_at', { withTimezone: false }).notNull(), + updatedAt: timestamp('updated_at', { withTimezone: false }).notNull(), +}); + +export const rates = pgTable('rates', { + id: integer('id').primaryKey().notNull(), + approves: boolean('approves'), + userId: integer('user_id').unique(), + reviewId: integer('review_id').unique(), + createdAt: timestamp('created_at', { withTimezone: false }).notNull(), + updatedAt: timestamp('updated_at', { withTimezone: false }).notNull(), +}); + +export const ratings = pgTable('ratings', { + id: integer('id').primaryKey().notNull(), + name: varchar('name', { length: 255}), + createdAt: timestamp('created_at', { withTimezone: false }).notNull(), + updatedAt: timestamp('updated_at', { withTimezone: false }).notNull(), + description: varchar('description', { length: 255}), +}); + +export const requirements = pgTable('requirements', { + id: bigint('id', {mode: 'number'}).primaryKey().notNull(), + description: text('description'), + goal: integer('goal'), + repeatable: integer('repeatable'), + createdAt: timestamp('created_at', { withTimezone: false }).notNull(), + updatedAt: timestamp('updated_at', { withTimezone: false }).notNull(), + actionId: bigint('action_id', {mode: 'number'}), +}); \ No newline at end of file diff --git a/src/db/schema/client.model.ts b/src/db/schema/client.model.ts deleted file mode 100644 index a5a25f917af9e3b135085c7cc1986a8367fc814c..0000000000000000000000000000000000000000 --- a/src/db/schema/client.model.ts +++ /dev/null @@ -1,64 +0,0 @@ -import { relations, sql } from 'drizzle-orm' -import { - pgTable, - timestamp, - uuid, - varchar, -} from 'drizzle-orm/pg-core' -import { createInsertSchema, createSelectSchema } from 'drizzle-zod' -import { z } from 'zod' -import creditCardTable, { - creditCardSchemas, -} from './credit-card.model' - -const clientTable = pgTable('client', { - id: uuid('id').primaryKey().defaultRandom(), - name: varchar('name', { length: 255 }).notNull(), - cnpj: varchar('cnpj', { length: 20 }).unique().notNull(), - industry: varchar('industry', { length: 50 }), - hqAddress: varchar('hq_address', { length: 255 }), - phone: varchar('phone', { length: 20 }), - email: varchar('email', { length: 255 }).unique(), - contactPerson: varchar('contact_person', { length: 255 }), - createdAt: timestamp('created_at', { mode: 'string' }) - .notNull() - .defaultNow(), - updatedAt: timestamp('updated_at', { mode: 'string' }) - .notNull() - .defaultNow() - .$onUpdate(() => sql`current_timestamp`), -}) - -export const clientTableRelations = relations( - clientTable, - ({ many }) => ({ - creditCards: many(creditCardTable), - }) -) - -const clientModelSchema = createSelectSchema(clientTable).extend({ - creditCards: creditCardSchemas.creditCardModelSchema - .array() - .optional(), -}) -const clientDtoSchema = clientModelSchema -const clientInputSchema = createInsertSchema(clientTable, { - email: (schema) => schema.email.email(), -}) -const clientUpdateSchema = clientInputSchema - .partial() - .required({ id: true }) - -export type ClientModel = z.infer<typeof clientModelSchema> -export type ClientDto = z.infer<typeof clientDtoSchema> -export type ClientInput = z.infer<typeof clientInputSchema> -export type ClientUpdate = z.infer<typeof clientUpdateSchema> - -export const clientSchemas = { - clientModelSchema, - clientDtoSchema, - clientInputSchema, - clientUpdateSchema, -} - -export default clientTable diff --git a/src/db/schema/collections.ts b/src/db/schema/collections.ts new file mode 100644 index 0000000000000000000000000000000000000000..9625a6a050272abfa445a75296309b73edf1c957 --- /dev/null +++ b/src/db/schema/collections.ts @@ -0,0 +1,44 @@ +import { + pgTable, + timestamp, + doublePrecision, + integer, + text, + varchar, + } from 'drizzle-orm/pg-core' + + +export const collectionItems = pgTable('collection_items', { + id: integer('id').primaryKey().notNull(), + collectionableType: varchar('collectionable_type', { length: 255}).unique(), + collectionableId: integer('collectionable_id').unique(), + collectionId: integer('collection_id').unique(), + position: integer('position'), + createdAt: timestamp('created_at', { withTimezone: false }).notNull(), + updatedAt: timestamp('updated_at', { withTimezone: false }).notNull(), + deletedAt: timestamp('deleted_at', { withTimezone: false }), +}); + +export const collections = pgTable('collections', { + id: integer('id').primaryKey().notNull(), + name: varchar('name', { length: 255}), + description: text('description'), + privacy: varchar('privacy', { length: 255}).default('private'), + ownerType: varchar('owner_type', { length: 255}), + ownerId: integer('owner_id'), + createdAt: timestamp('created_at', { withTimezone: false }).notNull(), + updatedAt: timestamp('updated_at', { withTimezone: false }).notNull(), + viewsCount: integer('views_count').default(0), + downloadsCount: integer('downloads_count').default(0), + likesCount: integer('likes_count').default(0), + sharesCount: integer('shares_count').default(0), + score: doublePrecision('score').default(0.0), + followsCount: integer('follows_count').default(0), + thumbnailFileName: varchar('thumbnail_file_name', { length: 255}), + thumbnailContentType: varchar('thumbnail_content_type', { length: 255}), + thumbnailFileSize: integer('thumbnail_file_size'), + thumbnailUpdatedAt: timestamp('thumbnail_updated_at', { withTimezone: false }), + deletedAt: timestamp('deleted_at', { withTimezone: false }), + reviewAverage: doublePrecision('review_average').default(0.0), + curator: varchar('curator', { length: 255}), +}); diff --git a/src/db/schema/complaints.ts b/src/db/schema/complaints.ts new file mode 100644 index 0000000000000000000000000000000000000000..72a3270d2ff0dc269a1016a6b32676dd880f2edc --- /dev/null +++ b/src/db/schema/complaints.ts @@ -0,0 +1,44 @@ +import { bigint } from 'drizzle-orm/pg-core' +import { + pgTable, + timestamp, + + integer, + text, + varchar, + } from 'drizzle-orm/pg-core' + + +export const complaintReasons = pgTable('complaint_reasons', { + id: integer('id').primaryKey().notNull(), + reason: text('reason'), + createdAt: timestamp('created_at', { withTimezone: false }).notNull(), + updatedAt: timestamp('updated_at', { withTimezone: false }).notNull(), + status: integer('status').default(0), + priority: integer('priority'), +}); + +export const complaintVotes = pgTable('complaint_votes', { + id: bigint('id', { mode: 'number'}).primaryKey().notNull(), + complainableType: varchar('complainable_type', { length: 255}).unique(), + complainableId: bigint('complainable_id', { mode: 'number'}).unique(), + pros: integer('pros'), + cons: integer('cons'), + createdAt: timestamp('created_at', { withTimezone: false }).notNull(), + updatedAt: timestamp('updated_at', { withTimezone: false }).notNull(), + deletedAt: timestamp('deleted_at', { withTimezone: false }), + userId: integer('user_id').unique(), +}); + +export const complaints = pgTable('complaints', { + id: integer('id').primaryKey().notNull(), + description: text('description'), + userId: integer('user_id').unique(), + complainableType: varchar('complainable_type', { length: 255}).unique(), + complainableId: integer('complainable_id').unique(), + complaintReasonId: integer('complaint_reason_id'), + createdAt: timestamp('created_at', { withTimezone: false }).notNull(), + updatedAt: timestamp('updated_at', { withTimezone: false }).notNull(), + deletedAt: timestamp('deleted_at', { withTimezone: false }), + state: integer('state').default(0), +}); \ No newline at end of file diff --git a/src/db/schema/contacts.ts b/src/db/schema/contacts.ts new file mode 100644 index 0000000000000000000000000000000000000000..83c40554d0016620bda025bcaadef24051b40489 --- /dev/null +++ b/src/db/schema/contacts.ts @@ -0,0 +1,36 @@ +import { + pgTable, + timestamp, + integer, + text, + json, + boolean, + varchar, +} from 'drizzle-orm/pg-core' + + +export const contacts = pgTable('contacts', { + id: integer('id').primaryKey().notNull(), + name: varchar('name', { length: 255 }), + email: varchar('email', { length: 255 }), + message: text('message'), + createdAt: timestamp('created_at', { withTimezone: false }).notNull(), + updatedAt: timestamp('updated_at', { withTimezone: false }).notNull(), +}); + + +export const emails = pgTable('emails', { + id: integer('id').primaryKey().notNull(), + subject: varchar('subject', { length: 255}), + body: text('body'), + emails: json('emails').default([]), + allUsers: boolean('all_users').default(false), + userId: integer('user_id'), + createdAt: timestamp('created_at', { withTimezone: false }).notNull(), + updatedAt: timestamp('updated_at', { withTimezone: false }).notNull(), +}); + +export const emailsRoles = pgTable('emails_roles', { + emailId: integer('email_id').notNull(), + roleId: integer('role_id').notNull(), +}); \ No newline at end of file diff --git a/src/db/schema/credit-card.model.ts b/src/db/schema/credit-card.model.ts deleted file mode 100644 index 3182b8ae7e9e2f760226b1e41b5ccdc2d6727d5a..0000000000000000000000000000000000000000 --- a/src/db/schema/credit-card.model.ts +++ /dev/null @@ -1,73 +0,0 @@ -import { - date, - pgTable, - timestamp, - uuid, - varchar, -} from 'drizzle-orm/pg-core' -import { createInsertSchema, createSelectSchema } from 'drizzle-zod' -import type { z } from 'zod' -import clientTable from './client.model' -import { relations, sql } from 'drizzle-orm' - -const creditCardTable = pgTable('credit_card', { - id: uuid('id').primaryKey().defaultRandom(), - clientId: uuid('client_id') - .references(() => clientTable.id, { onDelete: 'cascade' }) - .notNull(), - cardNumber: varchar('card_number', { length: 20 }) - .unique() - .notNull(), - cardholderName: varchar('cardholder_name', { - length: 255, - }).notNull(), - expirationDate: date('expiration_date', { - mode: 'string', - }).notNull(), - cvv: varchar('cvv', { length: 5 }).notNull(), - createdAt: timestamp('created_at', { - mode: 'string', - }) - .notNull() - .defaultNow(), - updatedAt: timestamp('updated_at', { - mode: 'string', - }) - .notNull() - .defaultNow() - .$onUpdate(() => sql`current_timestamp`), -}) - -export const creditCardTableRelations = relations( - creditCardTable, - ({ one }) => ({ - client: one(clientTable, { - fields: [creditCardTable.clientId], - references: [clientTable.id], - }), - }) -) - -const creditCardModelSchema = createSelectSchema(creditCardTable) -const creditCardDtoSchema = creditCardModelSchema.omit({ - cvv: true, - cardNumber: true, -}) -const creditCardInputSchema = createInsertSchema(creditCardTable) -const creditCardUpdateSchema = creditCardInputSchema - .partial() - .required({ id: true }) - -export type CreditCardModel = z.infer<typeof creditCardModelSchema> -export type CreditCardDto = z.infer<typeof creditCardDtoSchema> -export type CreditCardInput = z.infer<typeof creditCardInputSchema> -export type CreditCardUpdate = z.infer<typeof creditCardUpdateSchema> - -export const creditCardSchemas = { - creditCardModelSchema, - creditCardDtoSchema, - creditCardInputSchema, - creditCardUpdateSchema, -} - -export default creditCardTable diff --git a/src/db/schema/curator.ts b/src/db/schema/curator.ts new file mode 100644 index 0000000000000000000000000000000000000000..5274ecde1b7df58be147b8c94dba93f11149a759 --- /dev/null +++ b/src/db/schema/curator.ts @@ -0,0 +1,15 @@ +import { + pgTable, + timestamp, + integer, +} from 'drizzle-orm/pg-core' + + +export const curatorAssignments = pgTable('curator_assignments', { + id: integer('id').primaryKey().notNull(), + submissionId: integer('submission_id'), + userId: integer('user_id'), + status: integer('status').default(0), + createdAt: timestamp('created_at', { withTimezone: false }).notNull(), + updatedAt: timestamp('updated_at', { withTimezone: false }).notNull(), +}); diff --git a/src/db/schema/downloads.ts b/src/db/schema/downloads.ts new file mode 100644 index 0000000000000000000000000000000000000000..08ff75b061089c46029a1be5ff11a0da9b5c53b2 --- /dev/null +++ b/src/db/schema/downloads.ts @@ -0,0 +1,16 @@ +import { + pgTable, + timestamp, + integer, + varchar, + } from 'drizzle-orm/pg-core' + +export const downloads = pgTable('downloads', { + id: integer('id').primaryKey().notNull(), + downloadableType: varchar('downloadable_type', { length: 255}).unique(), + downloadableId: integer('downloadable_id').unique(), + userId: integer('user_id').unique(), + createdAt: timestamp('created_at', { withTimezone: false }).notNull(), + updatedAt: timestamp('updated_at', { withTimezone: false }).notNull(), + ip: varchar('ip', { length: 255}).unique().notNull(), +}); \ No newline at end of file diff --git a/src/db/schema/educationalStages.ts b/src/db/schema/educationalStages.ts new file mode 100644 index 0000000000000000000000000000000000000000..db2fb145831281e2f9bf1a847197b4fd0cdac1f5 --- /dev/null +++ b/src/db/schema/educationalStages.ts @@ -0,0 +1,18 @@ +import { + pgTable, + timestamp, + integer, + varchar, +} from 'drizzle-orm/pg-core' + +export const educationalStages = pgTable('educational_stages', { + id: integer('id').primaryKey().notNull(), + name: varchar('name', { length: 255}).unique(), + createdAt: timestamp('created_at', { withTimezone: false }).notNull(), + updatedAt: timestamp('updated_at', { withTimezone: false }).notNull(), +}); + +export const educationalStagesSearches = pgTable('educational_stages_searches', { + educationalStageId: integer('educational_stage_id').notNull(), + searchId: integer('search_id').notNull(), +}); \ No newline at end of file diff --git a/src/db/schema/institutions.ts b/src/db/schema/institutions.ts new file mode 100644 index 0000000000000000000000000000000000000000..8768aa3c95cf2aceff0fc86b68820d142b7c41f5 --- /dev/null +++ b/src/db/schema/institutions.ts @@ -0,0 +1,32 @@ +import { + pgTable, + timestamp, + integer, + text, + varchar, +} from 'drizzle-orm/pg-core' + +export const institutions = pgTable('institutions', { + id: integer('id').primaryKey().notNull(), + name: varchar('name', { length: 255}), + address: varchar('address', { length: 255}), + city: varchar('city', { length: 255}), + country: varchar('country', { length: 255}), + description: text('description'), + createdAt: timestamp('created_at', { withTimezone: false }).notNull(), + updatedAt: timestamp('updated_at', { withTimezone: false }).notNull(), + deletedAt: timestamp('deleted_at', { withTimezone: false }), + avatarFileName: varchar('avatar_file_name', { length: 255}), + avatarContentType: varchar('avatar_content_type', { length: 255}), + avatarFileSize: integer('avatar_file_size'), + avatarUpdatedAt: timestamp('avatar_updated_at', { withTimezone: false }), + learningObjectsCount: integer('learning_objects_count').default(0), +}); + +export const institutionsUsers = pgTable('institutions_users', { + id: integer('id').primaryKey().notNull(), + institutionId: integer('institution_id'), + userId: integer('user_id'), + createdAt: timestamp('created_at', { withTimezone: false }).notNull(), + updatedAt: timestamp('updated_at', { withTimezone: false }).notNull(), +}); \ No newline at end of file diff --git a/src/db/schema/items.ts b/src/db/schema/items.ts new file mode 100644 index 0000000000000000000000000000000000000000..05d2a3ebc332b9f08b5cd78840a9e5f63bb1003a --- /dev/null +++ b/src/db/schema/items.ts @@ -0,0 +1,25 @@ +import { + pgTable, + timestamp, + integer, + bigint, + varchar, + text +} from 'drizzle-orm/pg-core' + +export const items = pgTable('items', { + id: bigint('id', {mode: 'number'}).primaryKey().notNull(), + name: varchar('name', { length: 255}), + price: integer('price'), + discount: integer('discount').default(0), + description: text('description'), + state: integer('state').default(0), + itemType: integer('item_type'), + imageFileName: varchar('image_file_name', { length: 255}), + imageContentType: varchar('image_content_type', { length: 255}), + imageFileSize: bigint('image_file_size', {mode: 'number'}), + imageUpdatedAt: timestamp('image_updated_at', { withTimezone: false }), + createdAt: timestamp('created_at', { withTimezone: false }).notNull(), + updatedAt: timestamp('updated_at', { withTimezone: false }).notNull(), + achievementId: bigint('achievement_id', {mode: 'number'}), +}); \ No newline at end of file diff --git a/src/db/schema/languages.ts b/src/db/schema/languages.ts new file mode 100644 index 0000000000000000000000000000000000000000..2e4e3896ee0fd00b3c00f6dda2cec8b01207e4ba --- /dev/null +++ b/src/db/schema/languages.ts @@ -0,0 +1,24 @@ +import { + pgTable, + timestamp, + integer, + varchar, +} from 'drizzle-orm/pg-core' + +export const languages = pgTable('languages', { + id: integer('id').primaryKey().notNull(), + name: varchar('name', { length: 255}), + createdAt: timestamp('created_at', { withTimezone: false }).notNull(), + updatedAt: timestamp('updated_at', { withTimezone: false }).notNull(), + code: varchar('code', { length: 255}).unique(), +}); + +export const languagesLearningObjects = pgTable('languages_learning_objects', { + languageId: integer('language_id').notNull(), + learningObjectId: integer('learning_object_id').notNull(), +}); + +export const languagesSearches = pgTable('languages_searches', { + languageId: integer('language_id').notNull(), + searchId: integer('search_id').notNull(), +}); \ No newline at end of file diff --git a/src/db/schema/learningObjects.ts b/src/db/schema/learningObjects.ts new file mode 100644 index 0000000000000000000000000000000000000000..8e9f92aaf2408c25682cf00e9f69c9c68bf771f6 --- /dev/null +++ b/src/db/schema/learningObjects.ts @@ -0,0 +1,71 @@ +import { + pgTable, + timestamp, + integer, + text, + varchar, + doublePrecision, + jsonb, + boolean +} from 'drizzle-orm/pg-core' + +export const learningObjectAttachments = pgTable('learning_object_attachments', { + id: integer('id').primaryKey().notNull(), + name: varchar('name', { length: 255}), + link: varchar('link', { length: 255}), + retrieveLink: varchar('retrieve_link', { length: 255}), + description: text('description'), + format: varchar('format', { length: 255}), + mimeType: varchar('mime_type', { length: 255}), + size: integer('size'), + bundleName: varchar('bundle_name', { length: 255}), + learningObjectId: integer('learning_object_id'), + createdAt: timestamp('created_at', { withTimezone: false }).notNull(), + updatedAt: timestamp('updated_at', { withTimezone: false }).notNull(), + idDspace: varchar('id_dspace', { length: 255}), + thumbnailFileName: varchar('thumbnail_file_name', { length: 255}), + thumbnailContentType: varchar('thumbnail_content_type', { length: 255}), + thumbnailFileSize: integer('thumbnail_file_size'), + thumbnailUpdatedAt: timestamp('thumbnail_updated_at', { withTimezone: false }), + cacheLink: varchar('cache_link', { length: 255}), + infohash: varchar('infohash', { length: 255}), + learningObjectAttachmentId: integer('learning_object_attachment_id'), + learningObjectAttachmentIdSon: integer('learning_object_attachment_id_son'), + legacyDspaceId: varchar('legacy_dspace_id', { length: 255}), +}); + +export const learningObjects = pgTable('learning_objects', { + id: integer('id').primaryKey().notNull(), + idDspace: varchar('id_dspace', { length: 255}).unique(), + name: varchar('name', { length: 255}), + author: varchar('author', { length: 255}), + description: text('description'), + publishedAt: timestamp('published_at', { withTimezone: false }), + score: doublePrecision('score').default(0.0), + metadata: jsonb('metadata'), + publisherType: varchar('publisher_type', { length: 255}), + publisherId: integer('publisher_id'), + objectTypeId: integer('object_type_id'), + createdAt: timestamp('created_at', { withTimezone: false }).notNull(), + updatedAt: timestamp('updated_at', { withTimezone: false }).notNull(), + viewsCount: integer('views_count').default(0), + downloadsCount: integer('downloads_count').default(0), + likesCount: integer('likes_count').default(0), + sharesCount: integer('shares_count').default(0), + thumbnailFileName: varchar('thumbnail_file_name', { length: 255}), + thumbnailContentType: varchar('thumbnail_content_type', { length: 255}), + thumbnailFileSize: integer('thumbnail_file_size'), + thumbnailUpdatedAt: timestamp('thumbnail_updated_at', { withTimezone: false }), + attachmentId: integer('attachment_id'), + deletedAt: timestamp('deleted_at', { withTimezone: false }), + licenseId: integer('license_id'), + state: integer('state').default(0), + link: varchar('link', { length: 255}), + software: varchar('software', { length: 255}), + reviewAverage: doublePrecision('review_average').default(0.0), + curator: varchar('curator', { length: 255}), + magnetlink: varchar('magnetlink', { length: 255}), + termsOfService: boolean('terms_of_service'), + submissionId: integer('submission_id'), + legacyDspaceId: varchar('legacy_dspace_id', { length: 255}), +}); \ No newline at end of file diff --git a/src/db/schema/licenses.ts b/src/db/schema/licenses.ts new file mode 100644 index 0000000000000000000000000000000000000000..d7787fc790a3a7d2131be8da6b54481beb741422 --- /dev/null +++ b/src/db/schema/licenses.ts @@ -0,0 +1,17 @@ +import { + pgTable, + timestamp, + integer, + text, + varchar, +} from 'drizzle-orm/pg-core' + +export const licenses = pgTable('licenses', { + id: integer('id').primaryKey().notNull(), + name: varchar('name', { length: 255}), + description: text('description'), + imageUrl: varchar('image_url', { length: 255}), + url: varchar('url', { length: 255}), + createdAt: timestamp('created_at', { withTimezone: false }).notNull(), + updatedAt: timestamp('updated_at', { withTimezone: false }).notNull(), +}); \ No newline at end of file diff --git a/src/db/schema/mediaType.ts b/src/db/schema/mediaType.ts new file mode 100644 index 0000000000000000000000000000000000000000..f367fcdb433c39954ee777ac59adc9a3f254714f --- /dev/null +++ b/src/db/schema/mediaType.ts @@ -0,0 +1,17 @@ +import { + pgTable, + integer, + varchar, +} from 'drizzle-orm/pg-core' + +export const mimeTypes = pgTable('mime_types', { + id: integer('id').primaryKey().notNull(), + extension: varchar('extension', { length: 255}), + mimeType: varchar('mime_type', { length: 255}), +}); + +export const mimeTypesObjectTypes = pgTable('mime_types_object_types', { + id: integer('id').primaryKey().notNull(), + objectTypeId: integer('object_type_id'), + mimeTypeId: integer('mime_type_id'), +}); \ No newline at end of file diff --git a/src/db/schema/objectType.ts b/src/db/schema/objectType.ts new file mode 100644 index 0000000000000000000000000000000000000000..efc2258129abee44b9200bc4481e650d1623499a --- /dev/null +++ b/src/db/schema/objectType.ts @@ -0,0 +1,15 @@ +import { + pgTable, + integer, + varchar, +} from 'drizzle-orm/pg-core' + +export const objectTypes = pgTable('object_types', { + id: integer('id').primaryKey().notNull(), + name: varchar('name', { length: 255}), +}); + +export const objectTypesSearches = pgTable('object_types_searches', { + objectTypeId: integer('object_type_id').notNull(), + searchId: integer('search_id').notNull(), +}); \ No newline at end of file diff --git a/src/db/schema/packages.ts b/src/db/schema/packages.ts new file mode 100644 index 0000000000000000000000000000000000000000..5bffed7d86322d03c126027b0d10d4aa67c9bc21 --- /dev/null +++ b/src/db/schema/packages.ts @@ -0,0 +1,23 @@ +import { + pgTable, + integer, + varchar, + timestamp +} from 'drizzle-orm/pg-core' + +export const packageItems = pgTable('package_items', { + id: integer('id').primaryKey().notNull(), + packageId: integer('package_id'), + packageableType: varchar('packageable_type', { length: 255}), + packageableId: integer('packageable_id'), + createdAt: timestamp('created_at', { withTimezone: false }).notNull(), + updatedAt: timestamp('updated_at', { withTimezone: false }).notNull(), +}); + +export const packages = pgTable('packages', { + id: integer('id').primaryKey().notNull(), + packageItemsId: integer('package_items_id'), + createdAt: timestamp('created_at', { withTimezone: false }).notNull(), + updatedAt: timestamp('updated_at', { withTimezone: false }).notNull(), + filePath: varchar('file_path', { length: 255}), +}); diff --git a/src/db/schema/reviews.ts b/src/db/schema/reviews.ts new file mode 100644 index 0000000000000000000000000000000000000000..c05ccbb5b313e017527f0cbe0cb90de562a0f93c --- /dev/null +++ b/src/db/schema/reviews.ts @@ -0,0 +1,31 @@ +import { + pgTable, + timestamp, + integer, + varchar, + text +} from 'drizzle-orm/pg-core' + +export const reviewRatings = pgTable('review_ratings', { + id: integer('id').primaryKey().notNull(), + reviewId: integer('review_id').unique(), + ratingId: integer('rating_id').unique(), + value: integer('value'), + createdAt: timestamp('created_at', { withTimezone: false }).notNull(), + updatedAt: timestamp('updated_at', { withTimezone: false }).notNull(), +}); + +export const reviews = pgTable('reviews', { + id: integer('id').primaryKey().notNull(), + name: varchar('name', { length: 255}), + description: text('description'), + pros: text('pros'), + cons: text('cons'), + reviewableType: varchar('reviewable_type', { length: 255}), + reviewableId: integer('reviewable_id'), + userId: integer('user_id'), + createdAt: timestamp('created_at', { withTimezone: false }).notNull(), + updatedAt: timestamp('updated_at', { withTimezone: false }).notNull(), + ratesCount: integer('rates_count').default(0), + deletedAt: timestamp('deleted_at', { withTimezone: false }), +}); \ No newline at end of file diff --git a/src/db/schema/schemaMigrations.ts b/src/db/schema/schemaMigrations.ts new file mode 100644 index 0000000000000000000000000000000000000000..3b0c7b3a5e7c2217c6075e509f99465d0e41b2b0 --- /dev/null +++ b/src/db/schema/schemaMigrations.ts @@ -0,0 +1,8 @@ +import { + pgTable, + varchar, +} from 'drizzle-orm/pg-core' + +export const schemaMigrations = pgTable('schema_migrations', { + version: varchar('version', {length: 255}).notNull(), +}); \ No newline at end of file diff --git a/src/db/schema/schools.ts b/src/db/schema/schools.ts new file mode 100644 index 0000000000000000000000000000000000000000..536e39652109a56f2aa93387749df3c09c539e9c --- /dev/null +++ b/src/db/schema/schools.ts @@ -0,0 +1,17 @@ +import { + pgTable, + timestamp, + integer, + varchar, +} from 'drizzle-orm/pg-core' + +export const schools = pgTable('schools', { + id: integer('id').primaryKey().notNull(), + name: varchar('name', { length: 255}).notNull(), + phone: varchar('phone', { length: 255}), + uf: varchar('uf', { length: 255}), + city: varchar('city', { length: 255}), + inepId: varchar('inep_id', { length: 255}).unique(), + createdAt: timestamp('created_at', { withTimezone: false }).notNull(), + updatedAt: timestamp('updated_at', { withTimezone: false }).notNull(), +}); diff --git a/src/db/schema/searches.ts b/src/db/schema/searches.ts new file mode 100644 index 0000000000000000000000000000000000000000..5d740196f01c879d8b765c5c2bced4a99115d012 --- /dev/null +++ b/src/db/schema/searches.ts @@ -0,0 +1,26 @@ +import { + pgTable, + timestamp, + integer, + text, +} from 'drizzle-orm/pg-core' + +export const searches = pgTable('searches', { + id: integer('id').primaryKey().notNull(), + query: text('query'), + searchClass: text('search_class'), + userId: integer('user_id'), + createdAt: timestamp('created_at', { withTimezone: false }).notNull(), + updatedAt: timestamp('updated_at', { withTimezone: false }).notNull(), + numberOfResults: integer('number_of_results'), +}); + +export const searchesSubjects = pgTable('searches_subjects', { + searchId: integer('search_id').notNull(), + subjectId: integer('subject_id').notNull(), +}); + +export const searchesTags = pgTable('searches_tags', { + searchId: integer('search_id').notNull(), + tagId: integer('tag_id').notNull(), +}); diff --git a/src/db/schema/user.model.ts b/src/db/schema/user.model.ts deleted file mode 100644 index c161ebc0bf68ca87961cc7d89121ad0c9418a6f6..0000000000000000000000000000000000000000 --- a/src/db/schema/user.model.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { pgTable, uuid, varchar } from 'drizzle-orm/pg-core' -import { createInsertSchema, createSelectSchema } from 'drizzle-zod' -import { z } from 'zod' - -const userTable = pgTable('user', { - id: uuid('id').primaryKey().defaultRandom(), - username: varchar('username').unique().notNull(), - password: varchar('password').notNull(), - name: varchar('name').notNull(), -}) - -const userInputSchema = createInsertSchema(userTable) -const userModelSchema = createSelectSchema(userTable) -const userDtoSchema = createSelectSchema(userTable).omit({ - password: true, -}) - -export type UserInput = z.infer<typeof userInputSchema> -export type UserModel = z.infer<typeof userModelSchema> -export type UserDto = z.infer<typeof userDtoSchema> - -export const userSchemas = { - userInputSchema, - userModelSchema, - userDtoSchema, -} - -export default userTable diff --git a/src/db/schema/user.ts b/src/db/schema/user.ts new file mode 100644 index 0000000000000000000000000000000000000000..81b43d96943c6bebff76ffd87da40bd312968278 --- /dev/null +++ b/src/db/schema/user.ts @@ -0,0 +1,63 @@ +import { + pgTable, + timestamp, + integer, + varchar, + text, + doublePrecision, + boolean, + json +} from 'drizzle-orm/pg-core' + + +export const follows = pgTable('follows', { + id: integer('id').primaryKey().notNull(), + followableType: varchar('followable_type', { length: 255 }).unique(), + followableId: integer('followable_id').unique(), + userId: integer('user_id').unique(), + createdAt: timestamp('created_at', { withTimezone: false }).notNull(), + updatedAt: timestamp('updated_at', { withTimezone: false }).notNull(), +}); + +export const likes = pgTable('likes', { + id: integer('id').primaryKey().notNull(), + likeableType: varchar('likeable_type', {length: 255}).unique(), + likeableId: integer('likeable_id').unique(), + userId: integer('user_id').unique(), + createdAt: timestamp('created_at', { withTimezone: false }).notNull(), + updatedAt: timestamp('updated_at', { withTimezone: false }).notNull(), +}); + +export const roles = pgTable('roles', { + id: integer('id').primaryKey().notNull(), + name: varchar('name', { length: 255}).unique(), + description: text('description'), + createdAt: timestamp('created_at', { withTimezone: false }).notNull(), + updatedAt: timestamp('updated_at', { withTimezone: false }).notNull(), +}); + +export const rolesUsers = pgTable('roles_users', { + userId: integer('user_id').notNull(), + roleId: integer('role_id').notNull(), +}); + + +export const scoreUserCategories = pgTable('score_user_categories', { + id: integer('id').primaryKey().notNull(), + scoreId: integer('score_id').unique(), + userCategoryId: integer('user_category_id').unique(), + value: doublePrecision('value'), + createdAt: timestamp('created_at', { withTimezone: false }).notNull(), + updatedAt: timestamp('updated_at', { withTimezone: false }).notNull(), +}); + +export const scores = pgTable('scores', { + id: integer('id').primaryKey().notNull(), + name: varchar('name', { length: 255}), + code: varchar('code', { length: 255}).unique(), + weight: doublePrecision('weight'), + active: boolean('active').default(true), + createdAt: timestamp('created_at', { withTimezone: false }).notNull(), + updatedAt: timestamp('updated_at', { withTimezone: false }).notNull(), + scoreType: json('score_type').default([]), +}); diff --git a/src/db/seeds/client.seed.ts b/src/db/seeds/client.seed.ts deleted file mode 100644 index 94b48dae9551a9cece4ff7cf221ce99ca220c8b7..0000000000000000000000000000000000000000 --- a/src/db/seeds/client.seed.ts +++ /dev/null @@ -1,110 +0,0 @@ -import type db from '..' -import type { ClientInput } from '../schema/client.model' -import clientTable from '../schema/client.model' - -export default async function seed(db: db) { - await db.insert(clientTable).values(clientData) -} - -const clientData: ClientInput[] = [ - { - id: 'f1b9b3b4-0b3b-4b3b-8b3b-0b3b4b3b4b3b', - name: 'Acme Corp', - cnpj: '12.345.678/0001-91', - industry: 'Manufacturing', - hqAddress: '1234 Industry Rd, City', - phone: '123-456-7890', - email: 'contact@acmecorp.com', - contactPerson: 'John Doe', - }, - { - id: '12345678-1234-1234-1234-123456789012', - name: 'Example Corp', - cnpj: '98.765.432/0001-21', - industry: 'Technology', - hqAddress: '5678 Tech St, City', - phone: '987-654-3210', - email: 'contact@examplecorp.com', - contactPerson: 'Jane Smith', - }, - { - id: '87654321-4321-4321-4321-210987654321', - name: 'XYZ Corp', - cnpj: '11.223.344/0001-55', - industry: 'Finance', - hqAddress: '9876 Finance St, City', - phone: '555-555-5555', - email: 'contact@xyzcorp.com', - contactPerson: 'Bob Johnson', - }, - { - id: '98765432-2345-2345-2345-543210987654', - name: 'ABC Corp', - cnpj: '99.888.777/0001-33', - industry: 'Retail', - hqAddress: '5432 Retail St, City', - phone: '111-222-3333', - email: 'contact@abccorp.com', - contactPerson: 'Alice Brown', - }, - { - id: '23456789-3456-3456-3456-654321098765', - name: 'DEF Corp', - cnpj: '44.555.666/0001-44', - industry: 'Healthcare', - hqAddress: '8765 Healthcare St, City', - phone: '999-888-7777', - email: 'contact@defcorp.com', - contactPerson: 'David Wilson', - }, - { - id: '34567890-4567-4567-4567-765432109876', - name: 'GHI Corp', - cnpj: '77.888.999/0001-66', - industry: 'Education', - hqAddress: '2345 Education St, City', - phone: '333-444-5555', - email: 'contact@ghicorp.com', - contactPerson: 'Grace Thompson', - }, - { - id: '45678901-5678-5678-5678-876543210987', - name: 'JKL Corp', - cnpj: '22.333.444/0001-77', - industry: 'Hospitality', - hqAddress: '7654 Hospitality St, City', - phone: '777-666-5555', - email: 'contact@jklcorp.com', - contactPerson: 'James Davis', - }, - { - id: '56789012-6789-6789-6789-987654321098', - name: 'MNO Corp', - cnpj: '66.777.888/0001-88', - industry: 'Transportation', - hqAddress: '1234 Transportation St, City', - phone: '222-111-9999', - email: 'contact@mnocorp.com', - contactPerson: 'Mary Johnson', - }, - { - id: '67890123-7890-7890-7890-098765432109', - name: 'PQR Corp', - cnpj: '33.444.555/0001-99', - industry: 'Energy', - hqAddress: '9876 Energy St, City', - phone: '444-333-2222', - email: 'contact@pqrcorp.com', - contactPerson: 'Peter Wilson', - }, - { - id: '78901234-8901-8901-8901-987654321098', - name: 'STU Corp', - cnpj: '55.666.777/0001-00', - industry: 'Telecommunications', - hqAddress: '5432 Telecom St, City', - phone: '888-999-0000', - email: 'contact@stucorp.com', - contactPerson: 'Sarah Brown', - }, -] diff --git a/src/db/seeds/credit-card.seed.ts b/src/db/seeds/credit-card.seed.ts deleted file mode 100644 index 6230f3f0278c983ac38c750caba319fa276a18b6..0000000000000000000000000000000000000000 --- a/src/db/seeds/credit-card.seed.ts +++ /dev/null @@ -1,52 +0,0 @@ -import type db from '..' -import { creditCardTable } from '../schema' -import type { CreditCardInput } from '../schema/credit-card.model' - -export default async function seed(db: db) { - await db.insert(creditCardTable).values(creditCardData) -} - -const creditCardData: CreditCardInput[] = [ - { - clientId: 'f1b9b3b4-0b3b-4b3b-8b3b-0b3b4b3b4b3b', - cardNumber: '1234 5678 9012 3456', - cardholderName: 'John Doe', - expirationDate: '2025-12-31', - cvv: '123', - }, - { - clientId: 'f1b9b3b4-0b3b-4b3b-8b3b-0b3b4b3b4b3b', - cardNumber: '9876 5432 1098 7654', - cardholderName: 'Jane Smith', - expirationDate: '2024-06-30', - cvv: '456', - }, - { - clientId: '12345678-1234-1234-1234-123456789012', - cardNumber: '5555 4444 3333 2222', - cardholderName: 'Alice Johnson', - expirationDate: '2023-09-15', - cvv: '789', - }, - { - clientId: '12345678-1234-1234-1234-123456789012', - cardNumber: '1111 2222 3333 4444', - cardholderName: 'Bob Williams', - expirationDate: '2026-03-01', - cvv: '012', - }, - { - clientId: '12345678-1234-1234-1234-123456789012', - cardNumber: '9999 8888 7777 6666', - cardholderName: 'Sarah Davis', - expirationDate: '2025-11-30', - cvv: '345', - }, - { - clientId: '87654321-4321-4321-4321-210987654321', - cardNumber: '4444 5555 6666 7777', - cardholderName: 'Michael Brown', - expirationDate: '2022-07-10', - cvv: '678', - }, -] diff --git a/src/db/seeds/index.ts b/src/db/seeds/index.ts deleted file mode 100644 index 47dd12191d399d235cb53688dd0d23c51045b239..0000000000000000000000000000000000000000 --- a/src/db/seeds/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -export { default as userSeed } from './user.seed' -export { default as clientSeed } from './client.seed' -export { default as creditCardSeed } from './credit-card.seed' diff --git a/src/db/seeds/user.seed.ts b/src/db/seeds/user.seed.ts deleted file mode 100644 index 3a18be579440ca764606ac40cf7bf3a0cb9d40a3..0000000000000000000000000000000000000000 --- a/src/db/seeds/user.seed.ts +++ /dev/null @@ -1,20 +0,0 @@ -import type db from '@/db' -import userTable, { type UserInput } from '../schema/user.model' -import { hashPassword } from '../repo/auth.repo' - -export default async function seed(db: db) { - await db.insert(userTable).values(usersData) -} - -const usersData: UserInput[] = [ - { - username: 'admin', - password: hashPassword('1234mudar'), - name: 'Admin name', - }, - { - username: 'client user', - password: hashPassword('1234mudar'), - name: 'Client name', - }, -]