mirror of
https://github.com/internetee/registry.git
synced 2025-07-22 02:35:57 +02:00
Add db constraint
This commit is contained in:
parent
c013f563f3
commit
18e6f511aa
3 changed files with 211 additions and 204 deletions
|
@ -35,7 +35,7 @@ class Invoice < ActiveRecord::Base
|
|||
attribute :vat_rate, ::Type::VATRate.new
|
||||
|
||||
def set_invoice_number
|
||||
last_no = Invoice.order(number: :desc).where('number IS NOT NULL').limit(1).pluck(:number).first
|
||||
last_no = Invoice.order(number: :desc).limit(1).pluck(:number).first
|
||||
|
||||
if last_no && last_no >= Setting.invoice_number_min.to_i
|
||||
self.number = last_no + 1
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
class ChangeInvoicesNumberToNotNull < ActiveRecord::Migration
|
||||
def change
|
||||
change_column_null :invoices, :number, false
|
||||
end
|
||||
end
|
|
@ -963,7 +963,7 @@ CREATE TABLE public.invoices (
|
|||
buyer_email character varying,
|
||||
creator_str character varying,
|
||||
updator_str character varying,
|
||||
number integer,
|
||||
number integer NOT NULL,
|
||||
cancelled_at timestamp without time zone,
|
||||
total numeric(10,2) NOT NULL,
|
||||
in_directo boolean DEFAULT false,
|
||||
|
@ -4811,3 +4811,5 @@ INSERT INTO schema_migrations (version) VALUES ('20190620084334');
|
|||
|
||||
INSERT INTO schema_migrations (version) VALUES ('20190811184334');
|
||||
|
||||
INSERT INTO schema_migrations (version) VALUES ('20190811195814');
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue