Initial commit - Fase 1: Setup Rails + Docker
This commit is contained in:
27
db/migrate/20260101000001_create_users.rb
Normal file
27
db/migrate/20260101000001_create_users.rb
Normal file
@@ -0,0 +1,27 @@
|
||||
class CreateUsers < ActiveRecord::Migration[7.1]
|
||||
def change
|
||||
create_table :users do |t|
|
||||
# Devise campos padrão
|
||||
t.string :email, null: false, default: ""
|
||||
t.string :encrypted_password, null: false, default: ""
|
||||
t.string :reset_password_token
|
||||
t.datetime :reset_password_sent_at
|
||||
t.datetime :remember_created_at
|
||||
|
||||
# Campos customizados
|
||||
t.string :nome, null: false
|
||||
t.string :telefone
|
||||
t.string :pin_code, limit: 4 # apenas motoristas
|
||||
t.integer :role, null: false, default: 3 # 0=admin,1=gerente,2=operador,3=motorista
|
||||
t.boolean :ativo, null: false, default: true
|
||||
t.string :tema_preferido, default: 'dark' # dark | light
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
add_index :users, :email, unique: true
|
||||
add_index :users, :reset_password_token, unique: true
|
||||
add_index :users, :pin_code
|
||||
add_index :users, :role
|
||||
end
|
||||
end
|
||||
14
db/migrate/20260101000002_create_configuracoes.rb
Normal file
14
db/migrate/20260101000002_create_configuracoes.rb
Normal file
@@ -0,0 +1,14 @@
|
||||
class CreateConfiguracoes < ActiveRecord::Migration[7.1]
|
||||
def change
|
||||
create_table :configuracoes do |t|
|
||||
t.string :chave, null: false
|
||||
t.string :valor, null: false
|
||||
t.string :descricao
|
||||
t.integer :updated_by # user_id de quem editou por último
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
add_index :configuracoes, :chave, unique: true
|
||||
end
|
||||
end
|
||||
23
db/migrate/20260101000003_create_consolidacoes.rb
Normal file
23
db/migrate/20260101000003_create_consolidacoes.rb
Normal file
@@ -0,0 +1,23 @@
|
||||
class CreateConsolidacoes < ActiveRecord::Migration[7.1]
|
||||
def change
|
||||
create_table :consolidacoes do |t|
|
||||
t.string :nome, null: false
|
||||
t.date :data_inicio, null: false
|
||||
t.date :data_fim, null: false
|
||||
t.integer :status, null: false, default: 0 # 0=rascunho,1=finalizada,2=arquivada
|
||||
t.decimal :valor_total, precision: 10, scale: 2, default: 0
|
||||
t.integer :created_by, null: false # user_id
|
||||
t.integer :finalizado_por # user_id
|
||||
t.datetime :finalizado_em
|
||||
t.datetime :deleted_at # soft delete
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
add_index :consolidacoes, :status
|
||||
add_index :consolidacoes, :data_inicio
|
||||
add_index :consolidacoes, :data_fim
|
||||
add_index :consolidacoes, :deleted_at
|
||||
add_index :consolidacoes, :created_by
|
||||
end
|
||||
end
|
||||
17
db/migrate/20260101000004_create_consolidacao_motoristas.rb
Normal file
17
db/migrate/20260101000004_create_consolidacao_motoristas.rb
Normal file
@@ -0,0 +1,17 @@
|
||||
class CreateConsolidacaoMotoristas < ActiveRecord::Migration[7.1]
|
||||
def change
|
||||
create_table :consolidacao_motoristas do |t|
|
||||
t.references :consolidacao, null: false, foreign_key: true
|
||||
t.string :motorista_nome, null: false # driver da tabela existente
|
||||
t.decimal :valor_total, precision: 10, scale: 2, default: 0
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
add_index :consolidacao_motoristas, :motorista_nome
|
||||
add_index :consolidacao_motoristas,
|
||||
[:consolidacao_id, :motorista_nome],
|
||||
unique: true,
|
||||
name: 'idx_consolidacao_motorista_unique'
|
||||
end
|
||||
end
|
||||
23
db/migrate/20260101000005_create_consolidacao_entregas.rb
Normal file
23
db/migrate/20260101000005_create_consolidacao_entregas.rb
Normal file
@@ -0,0 +1,23 @@
|
||||
class CreateConsolidacaoEntregas < ActiveRecord::Migration[7.1]
|
||||
def change
|
||||
create_table :consolidacao_entregas do |t|
|
||||
t.references :consolidacao, null: false, foreign_key: true
|
||||
t.string :tracking_id, null: false # FK lógico para db_reem_simplerout_2026
|
||||
t.string :motorista_nome, null: false
|
||||
t.integer :tipo, null: false, default: 0
|
||||
# 0=entrega_normal, 1=retirada, 2=bonus, 3=desconto
|
||||
t.decimal :valor_aplicado, precision: 10, scale: 2, null: false
|
||||
t.integer :created_by # user_id de quem classificou
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
add_index :consolidacao_entregas, :tracking_id
|
||||
add_index :consolidacao_entregas, :motorista_nome
|
||||
add_index :consolidacao_entregas, :tipo
|
||||
add_index :consolidacao_entregas,
|
||||
[:consolidacao_id, :tracking_id],
|
||||
unique: true,
|
||||
name: 'idx_consolidacao_entrega_unique'
|
||||
end
|
||||
end
|
||||
13
db/migrate/20260101000006_create_historico_estimados.rb
Normal file
13
db/migrate/20260101000006_create_historico_estimados.rb
Normal file
@@ -0,0 +1,13 @@
|
||||
class CreateHistoricoEstimados < ActiveRecord::Migration[7.1]
|
||||
def change
|
||||
create_table :historico_estimados do |t|
|
||||
t.datetime :data_hora, null: false
|
||||
t.decimal :valor_total_estimado, precision: 10, scale: 2, null: false
|
||||
t.integer :entregas_contadas, null: false, default: 0
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
add_index :historico_estimados, :data_hora
|
||||
end
|
||||
end
|
||||
22
db/migrate/20260101000007_create_auditoria_logs.rb
Normal file
22
db/migrate/20260101000007_create_auditoria_logs.rb
Normal file
@@ -0,0 +1,22 @@
|
||||
class CreateAuditoriaLogs < ActiveRecord::Migration[7.1]
|
||||
def change
|
||||
create_table :auditoria_logs do |t|
|
||||
t.integer :user_id, null: false
|
||||
t.string :acao, null: false # criar, editar, finalizar, arquivar, etc.
|
||||
t.string :entidade, null: false # Consolidacao, ConsolidacaoEntrega, etc.
|
||||
t.integer :entidade_id
|
||||
t.jsonb :dados_anteriores, default: {}
|
||||
t.jsonb :dados_novos, default: {}
|
||||
t.string :ip_address
|
||||
t.string :user_agent
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
add_index :auditoria_logs, :user_id
|
||||
add_index :auditoria_logs, :acao
|
||||
add_index :auditoria_logs, :entidade
|
||||
add_index :auditoria_logs, [:entidade, :entidade_id]
|
||||
add_index :auditoria_logs, :created_at
|
||||
end
|
||||
end
|
||||
47
db/seeds.rb
Normal file
47
db/seeds.rb
Normal file
@@ -0,0 +1,47 @@
|
||||
# db/seeds.rb
|
||||
# Dados iniciais do sistema Gade Hospitalar
|
||||
# Execute com: bundle exec rails db:seed
|
||||
|
||||
puts "🌱 Criando dados iniciais..."
|
||||
|
||||
# ── Usuário Admin padrão ─────────────────────────────────────
|
||||
admin = User.find_or_create_by!(email: 'admin@gade.com') do |u|
|
||||
u.nome = 'Administrador Gade'
|
||||
u.password = 'Gade@2026!'
|
||||
u.role = :admin
|
||||
u.ativo = true
|
||||
end
|
||||
puts " ✅ Admin criado: #{admin.email} / senha: Gade@2026!"
|
||||
|
||||
# ── Usuário Gerente de exemplo ───────────────────────────────
|
||||
gerente = User.find_or_create_by!(email: 'gerente@gade.com') do |u|
|
||||
u.nome = 'Gerente Gade'
|
||||
u.password = 'Gade@2026!'
|
||||
u.role = :gerente
|
||||
u.ativo = true
|
||||
end
|
||||
puts " ✅ Gerente criado: #{gerente.email}"
|
||||
|
||||
# ── Configurações de preço padrão ────────────────────────────
|
||||
configs = [
|
||||
{ chave: 'preco_entrega', valor: '15.00', descricao: 'Valor pago por entrega bem-sucedida (R$)' },
|
||||
{ chave: 'preco_retirada', valor: '20.00', descricao: 'Valor pago por retirada de equipamento (R$)' },
|
||||
{ chave: 'preco_bonus', valor: '10.00', descricao: 'Valor de bônus por meta/critério (R$)' },
|
||||
{ chave: 'preco_desconto', valor: '15.00', descricao: 'Valor descontado por problema (R$)' },
|
||||
{ chave: 'notificacao_whatsapp', valor: 'false', descricao: 'Notificações via WhatsApp (true/false)' },
|
||||
{ chave: 'notificacao_email', valor: 'false', descricao: 'Notificações via e-mail (true/false)' },
|
||||
{ chave: 'empresa_nome', valor: 'Gade Hospitalar', descricao: 'Nome da empresa exibido no sistema' },
|
||||
]
|
||||
|
||||
configs.each do |cfg|
|
||||
Configuracao.find_or_create_by!(chave: cfg[:chave]) do |c|
|
||||
c.valor = cfg[:valor]
|
||||
c.descricao = cfg[:descricao]
|
||||
end
|
||||
puts " ✅ Config: #{cfg[:chave]} = #{cfg[:valor]}"
|
||||
end
|
||||
|
||||
puts ""
|
||||
puts "✅ Seeds concluídos!"
|
||||
puts " Admin: admin@gade.com / Gade@2026!"
|
||||
puts " ⚠️ ALTERE A SENHA DO ADMIN NO PRIMEIRO ACESSO!"
|
||||
Reference in New Issue
Block a user