refactor(schema): atualizar referências para os novos nomes de tabelas
- Atualizar schema.ts com os novos nomes das tabelas em português - Manter exportações e relações consistentes
This commit is contained in:
133
db/schema.ts
133
db/schema.ts
@@ -100,7 +100,7 @@ export const verification = pgTable("verification", {
|
|||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
export const userPreferences = pgTable("user_preferences", {
|
export const preferenciasUsuario = pgTable("preferencias_usuario", {
|
||||||
id: uuid("id").primaryKey().default(sql`gen_random_uuid()`),
|
id: uuid("id").primaryKey().default(sql`gen_random_uuid()`),
|
||||||
userId: text("user_id")
|
userId: text("user_id")
|
||||||
.notNull()
|
.notNull()
|
||||||
@@ -229,8 +229,8 @@ export const pagadores = pgTable(
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
export const pagadorShares = pgTable(
|
export const compartilhamentosPagador = pgTable(
|
||||||
"pagador_shares",
|
"compartilhamentos_pagador",
|
||||||
{
|
{
|
||||||
id: uuid("id").primaryKey().default(sql`gen_random_uuid()`),
|
id: uuid("id").primaryKey().default(sql`gen_random_uuid()`),
|
||||||
pagadorId: uuid("pagador_id")
|
pagadorId: uuid("pagador_id")
|
||||||
@@ -251,10 +251,9 @@ export const pagadorShares = pgTable(
|
|||||||
.defaultNow(),
|
.defaultNow(),
|
||||||
},
|
},
|
||||||
(table) => ({
|
(table) => ({
|
||||||
uniquePagadorShare: uniqueIndex("pagador_shares_unique").on(
|
uniqueCompartilhamentoPagador: uniqueIndex(
|
||||||
table.pagadorId,
|
"compartilhamentos_pagador_unique",
|
||||||
table.sharedWithUserId,
|
).on(table.pagadorId, table.sharedWithUserId),
|
||||||
),
|
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -372,8 +371,8 @@ export const anotacoes = pgTable("anotacoes", {
|
|||||||
.references(() => user.id, { onDelete: "cascade" }),
|
.references(() => user.id, { onDelete: "cascade" }),
|
||||||
});
|
});
|
||||||
|
|
||||||
export const savedInsights = pgTable(
|
export const insightsSalvos = pgTable(
|
||||||
"saved_insights",
|
"insights_salvos",
|
||||||
{
|
{
|
||||||
id: uuid("id").primaryKey().default(sql`gen_random_uuid()`),
|
id: uuid("id").primaryKey().default(sql`gen_random_uuid()`),
|
||||||
userId: text("user_id")
|
userId: text("user_id")
|
||||||
@@ -396,7 +395,7 @@ export const savedInsights = pgTable(
|
|||||||
.defaultNow(),
|
.defaultNow(),
|
||||||
},
|
},
|
||||||
(table) => ({
|
(table) => ({
|
||||||
userPeriodIdx: uniqueIndex("saved_insights_user_period_idx").on(
|
userPeriodIdx: uniqueIndex("insights_salvos_user_period_idx").on(
|
||||||
table.userId,
|
table.userId,
|
||||||
table.period,
|
table.period,
|
||||||
),
|
),
|
||||||
@@ -405,8 +404,8 @@ export const savedInsights = pgTable(
|
|||||||
|
|
||||||
// ===================== OPENSHEETS COMPANION =====================
|
// ===================== OPENSHEETS COMPANION =====================
|
||||||
|
|
||||||
export const apiTokens = pgTable(
|
export const tokensApi = pgTable(
|
||||||
"api_tokens",
|
"tokens_api",
|
||||||
{
|
{
|
||||||
id: uuid("id").primaryKey().default(sql`gen_random_uuid()`),
|
id: uuid("id").primaryKey().default(sql`gen_random_uuid()`),
|
||||||
userId: text("user_id")
|
userId: text("user_id")
|
||||||
@@ -424,13 +423,13 @@ export const apiTokens = pgTable(
|
|||||||
.defaultNow(),
|
.defaultNow(),
|
||||||
},
|
},
|
||||||
(table) => ({
|
(table) => ({
|
||||||
userIdIdx: index("api_tokens_user_id_idx").on(table.userId),
|
userIdIdx: index("tokens_api_user_id_idx").on(table.userId),
|
||||||
tokenHashIdx: uniqueIndex("api_tokens_token_hash_idx").on(table.tokenHash),
|
tokenHashIdx: uniqueIndex("tokens_api_token_hash_idx").on(table.tokenHash),
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
export const inboxItems = pgTable(
|
export const preLancamentos = pgTable(
|
||||||
"inbox_items",
|
"pre_lancamentos",
|
||||||
{
|
{
|
||||||
id: uuid("id").primaryKey().default(sql`gen_random_uuid()`),
|
id: uuid("id").primaryKey().default(sql`gen_random_uuid()`),
|
||||||
userId: text("user_id")
|
userId: text("user_id")
|
||||||
@@ -481,19 +480,19 @@ export const inboxItems = pgTable(
|
|||||||
.defaultNow(),
|
.defaultNow(),
|
||||||
},
|
},
|
||||||
(table) => ({
|
(table) => ({
|
||||||
userIdStatusIdx: index("inbox_items_user_id_status_idx").on(
|
userIdStatusIdx: index("pre_lancamentos_user_id_status_idx").on(
|
||||||
table.userId,
|
table.userId,
|
||||||
table.status,
|
table.status,
|
||||||
),
|
),
|
||||||
userIdCreatedAtIdx: index("inbox_items_user_id_created_at_idx").on(
|
userIdCreatedAtIdx: index("pre_lancamentos_user_id_created_at_idx").on(
|
||||||
table.userId,
|
table.userId,
|
||||||
table.createdAt,
|
table.createdAt,
|
||||||
),
|
),
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
export const installmentAnticipations = pgTable(
|
export const antecipacoesParcelas = pgTable(
|
||||||
"installment_anticipations",
|
"antecipacoes_parcelas",
|
||||||
{
|
{
|
||||||
id: uuid("id").primaryKey().default(sql`gen_random_uuid()`),
|
id: uuid("id").primaryKey().default(sql`gen_random_uuid()`),
|
||||||
seriesId: uuid("series_id").notNull(),
|
seriesId: uuid("series_id").notNull(),
|
||||||
@@ -528,10 +527,8 @@ export const installmentAnticipations = pgTable(
|
|||||||
.defaultNow(),
|
.defaultNow(),
|
||||||
},
|
},
|
||||||
(table) => ({
|
(table) => ({
|
||||||
seriesIdIdx: index("installment_anticipations_series_id_idx").on(
|
seriesIdIdx: index("antecipacoes_parcelas_series_id_idx").on(table.seriesId),
|
||||||
table.seriesId,
|
userIdIdx: index("antecipacoes_parcelas_user_id_idx").on(table.userId),
|
||||||
),
|
|
||||||
userIdIdx: index("installment_anticipations_user_id_idx").on(table.userId),
|
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -556,7 +553,7 @@ export const lancamentos = pgTable(
|
|||||||
isDivided: boolean("dividido").default(false),
|
isDivided: boolean("dividido").default(false),
|
||||||
isAnticipated: boolean("antecipado").default(false),
|
isAnticipated: boolean("antecipado").default(false),
|
||||||
anticipationId: uuid("antecipacao_id").references(
|
anticipationId: uuid("antecipacao_id").references(
|
||||||
() => installmentAnticipations.id,
|
() => antecipacoesParcelas.id,
|
||||||
{ onDelete: "set null" },
|
{ onDelete: "set null" },
|
||||||
),
|
),
|
||||||
createdAt: timestamp("created_at", {
|
createdAt: timestamp("created_at", {
|
||||||
@@ -626,9 +623,9 @@ export const userRelations = relations(user, ({ many, one }) => ({
|
|||||||
lancamentos: many(lancamentos),
|
lancamentos: many(lancamentos),
|
||||||
orcamentos: many(orcamentos),
|
orcamentos: many(orcamentos),
|
||||||
pagadores: many(pagadores),
|
pagadores: many(pagadores),
|
||||||
installmentAnticipations: many(installmentAnticipations),
|
antecipacoesParcelas: many(antecipacoesParcelas),
|
||||||
apiTokens: many(apiTokens),
|
tokensApi: many(tokensApi),
|
||||||
inboxItems: many(inboxItems),
|
preLancamentos: many(preLancamentos),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
export const accountRelations = relations(account, ({ one }) => ({
|
export const accountRelations = relations(account, ({ one }) => ({
|
||||||
@@ -669,23 +666,26 @@ export const pagadoresRelations = relations(pagadores, ({ one, many }) => ({
|
|||||||
references: [user.id],
|
references: [user.id],
|
||||||
}),
|
}),
|
||||||
lancamentos: many(lancamentos),
|
lancamentos: many(lancamentos),
|
||||||
shares: many(pagadorShares),
|
compartilhamentos: many(compartilhamentosPagador),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
export const pagadorSharesRelations = relations(pagadorShares, ({ one }) => ({
|
export const compartilhamentosPagadorRelations = relations(
|
||||||
pagador: one(pagadores, {
|
compartilhamentosPagador,
|
||||||
fields: [pagadorShares.pagadorId],
|
({ one }) => ({
|
||||||
references: [pagadores.id],
|
pagador: one(pagadores, {
|
||||||
|
fields: [compartilhamentosPagador.pagadorId],
|
||||||
|
references: [pagadores.id],
|
||||||
|
}),
|
||||||
|
sharedWithUser: one(user, {
|
||||||
|
fields: [compartilhamentosPagador.sharedWithUserId],
|
||||||
|
references: [user.id],
|
||||||
|
}),
|
||||||
|
createdByUser: one(user, {
|
||||||
|
fields: [compartilhamentosPagador.createdByUserId],
|
||||||
|
references: [user.id],
|
||||||
|
}),
|
||||||
}),
|
}),
|
||||||
sharedWithUser: one(user, {
|
);
|
||||||
fields: [pagadorShares.sharedWithUserId],
|
|
||||||
references: [user.id],
|
|
||||||
}),
|
|
||||||
createdByUser: one(user, {
|
|
||||||
fields: [pagadorShares.createdByUserId],
|
|
||||||
references: [user.id],
|
|
||||||
}),
|
|
||||||
}));
|
|
||||||
|
|
||||||
export const cartoesRelations = relations(cartoes, ({ one, many }) => ({
|
export const cartoesRelations = relations(cartoes, ({ one, many }) => ({
|
||||||
user: one(user, {
|
user: one(user, {
|
||||||
@@ -729,27 +729,27 @@ export const anotacoesRelations = relations(anotacoes, ({ one }) => ({
|
|||||||
}),
|
}),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
export const savedInsightsRelations = relations(savedInsights, ({ one }) => ({
|
export const insightsSalvosRelations = relations(insightsSalvos, ({ one }) => ({
|
||||||
user: one(user, {
|
user: one(user, {
|
||||||
fields: [savedInsights.userId],
|
fields: [insightsSalvos.userId],
|
||||||
references: [user.id],
|
references: [user.id],
|
||||||
}),
|
}),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
export const apiTokensRelations = relations(apiTokens, ({ one }) => ({
|
export const tokensApiRelations = relations(tokensApi, ({ one }) => ({
|
||||||
user: one(user, {
|
user: one(user, {
|
||||||
fields: [apiTokens.userId],
|
fields: [tokensApi.userId],
|
||||||
references: [user.id],
|
references: [user.id],
|
||||||
}),
|
}),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
export const inboxItemsRelations = relations(inboxItems, ({ one }) => ({
|
export const preLancamentosRelations = relations(preLancamentos, ({ one }) => ({
|
||||||
user: one(user, {
|
user: one(user, {
|
||||||
fields: [inboxItems.userId],
|
fields: [preLancamentos.userId],
|
||||||
references: [user.id],
|
references: [user.id],
|
||||||
}),
|
}),
|
||||||
lancamento: one(lancamentos, {
|
lancamento: one(lancamentos, {
|
||||||
fields: [inboxItems.lancamentoId],
|
fields: [preLancamentos.lancamentoId],
|
||||||
references: [lancamentos.id],
|
references: [lancamentos.id],
|
||||||
}),
|
}),
|
||||||
}));
|
}));
|
||||||
@@ -775,29 +775,29 @@ export const lancamentosRelations = relations(lancamentos, ({ one }) => ({
|
|||||||
fields: [lancamentos.pagadorId],
|
fields: [lancamentos.pagadorId],
|
||||||
references: [pagadores.id],
|
references: [pagadores.id],
|
||||||
}),
|
}),
|
||||||
anticipation: one(installmentAnticipations, {
|
anticipation: one(antecipacoesParcelas, {
|
||||||
fields: [lancamentos.anticipationId],
|
fields: [lancamentos.anticipationId],
|
||||||
references: [installmentAnticipations.id],
|
references: [antecipacoesParcelas.id],
|
||||||
}),
|
}),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
export const installmentAnticipationsRelations = relations(
|
export const antecipacoesParcRelations = relations(
|
||||||
installmentAnticipations,
|
antecipacoesParcelas,
|
||||||
({ one, many }) => ({
|
({ one, many }) => ({
|
||||||
user: one(user, {
|
user: one(user, {
|
||||||
fields: [installmentAnticipations.userId],
|
fields: [antecipacoesParcelas.userId],
|
||||||
references: [user.id],
|
references: [user.id],
|
||||||
}),
|
}),
|
||||||
lancamento: one(lancamentos, {
|
lancamento: one(lancamentos, {
|
||||||
fields: [installmentAnticipations.lancamentoId],
|
fields: [antecipacoesParcelas.lancamentoId],
|
||||||
references: [lancamentos.id],
|
references: [lancamentos.id],
|
||||||
}),
|
}),
|
||||||
pagador: one(pagadores, {
|
pagador: one(pagadores, {
|
||||||
fields: [installmentAnticipations.pagadorId],
|
fields: [antecipacoesParcelas.pagadorId],
|
||||||
references: [pagadores.id],
|
references: [pagadores.id],
|
||||||
}),
|
}),
|
||||||
categoria: one(categorias, {
|
categoria: one(categorias, {
|
||||||
fields: [installmentAnticipations.categoriaId],
|
fields: [antecipacoesParcelas.categoriaId],
|
||||||
references: [categorias.id],
|
references: [categorias.id],
|
||||||
}),
|
}),
|
||||||
}),
|
}),
|
||||||
@@ -808,8 +808,10 @@ export type NewUser = typeof user.$inferInsert;
|
|||||||
export type Account = typeof account.$inferSelect;
|
export type Account = typeof account.$inferSelect;
|
||||||
export type Session = typeof session.$inferSelect;
|
export type Session = typeof session.$inferSelect;
|
||||||
export type Verification = typeof verification.$inferSelect;
|
export type Verification = typeof verification.$inferSelect;
|
||||||
export type UserPreferences = typeof userPreferences.$inferSelect;
|
export type PreferenciasUsuario = typeof preferenciasUsuario.$inferSelect;
|
||||||
export type NewUserPreferences = typeof userPreferences.$inferInsert;
|
export type NovasPreferenciasUsuario = typeof preferenciasUsuario.$inferInsert;
|
||||||
|
export type CompartilhamentoPagador =
|
||||||
|
typeof compartilhamentosPagador.$inferSelect;
|
||||||
export type Conta = typeof contas.$inferSelect;
|
export type Conta = typeof contas.$inferSelect;
|
||||||
export type Categoria = typeof categorias.$inferSelect;
|
export type Categoria = typeof categorias.$inferSelect;
|
||||||
export type Pagador = typeof pagadores.$inferSelect;
|
export type Pagador = typeof pagadores.$inferSelect;
|
||||||
@@ -817,11 +819,10 @@ export type Cartao = typeof cartoes.$inferSelect;
|
|||||||
export type Fatura = typeof faturas.$inferSelect;
|
export type Fatura = typeof faturas.$inferSelect;
|
||||||
export type Orcamento = typeof orcamentos.$inferSelect;
|
export type Orcamento = typeof orcamentos.$inferSelect;
|
||||||
export type Anotacao = typeof anotacoes.$inferSelect;
|
export type Anotacao = typeof anotacoes.$inferSelect;
|
||||||
export type SavedInsight = typeof savedInsights.$inferSelect;
|
export type InsightSalvo = typeof insightsSalvos.$inferSelect;
|
||||||
export type Lancamento = typeof lancamentos.$inferSelect;
|
export type Lancamento = typeof lancamentos.$inferSelect;
|
||||||
export type InstallmentAnticipation =
|
export type AntecipacaoParcela = typeof antecipacoesParcelas.$inferSelect;
|
||||||
typeof installmentAnticipations.$inferSelect;
|
export type TokenApi = typeof tokensApi.$inferSelect;
|
||||||
export type ApiToken = typeof apiTokens.$inferSelect;
|
export type NovoTokenApi = typeof tokensApi.$inferInsert;
|
||||||
export type NewApiToken = typeof apiTokens.$inferInsert;
|
export type PreLancamento = typeof preLancamentos.$inferSelect;
|
||||||
export type InboxItem = typeof inboxItems.$inferSelect;
|
export type NovoPreLancamento = typeof preLancamentos.$inferInsert;
|
||||||
export type NewInboxItem = typeof inboxItems.$inferInsert;
|
|
||||||
|
|||||||
Reference in New Issue
Block a user