fix: normalize SQL
This commit is contained in:
parent
e846f5a165
commit
742913db36
4 changed files with 16 additions and 16 deletions
|
|
@ -2,22 +2,22 @@ const db = require('./db')
|
||||||
const uuid = require('uuid')
|
const uuid = require('uuid')
|
||||||
|
|
||||||
function getAvailableCoupons () {
|
function getAvailableCoupons () {
|
||||||
const sql = `select * from coupons where soft_deleted=false`
|
const sql = `SELECT * FROM coupons WHERE soft_deleted=false`
|
||||||
return db.any(sql)
|
return db.any(sql)
|
||||||
}
|
}
|
||||||
|
|
||||||
function getCoupon (code) {
|
function getCoupon (code) {
|
||||||
const sql = `select * from coupons where code=$1 and soft_deleted=false`
|
const sql = `SELECT * FROM coupons WHERE code=$1 AND soft_deleted=false`
|
||||||
return db.oneOrNone(sql, [code])
|
return db.oneOrNone(sql, [code])
|
||||||
}
|
}
|
||||||
|
|
||||||
function createCoupon (code, discount) {
|
function createCoupon (code, discount) {
|
||||||
const sql = `insert into coupons (id, code, discount) values ($1, $2, $3) returning *`
|
const sql = `INSERT INTO coupons (id, code, discount) VALUES ($1, $2, $3) RETURNING *`
|
||||||
return db.one(sql, [uuid.v4(), code, discount])
|
return db.one(sql, [uuid.v4(), code, discount])
|
||||||
}
|
}
|
||||||
|
|
||||||
function softDeleteCoupon (couponId) {
|
function softDeleteCoupon (couponId) {
|
||||||
const sql = `update coupons set soft_deleted=true where id=$1`
|
const sql = `UPDATE coupons SET soft_deleted=true WHERE id=$1`
|
||||||
return db.none(sql, [couponId])
|
return db.none(sql, [couponId])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,12 +3,12 @@ var db = require('./db')
|
||||||
exports.up = function (next) {
|
exports.up = function (next) {
|
||||||
const sql =
|
const sql =
|
||||||
[
|
[
|
||||||
`create table coupons (
|
`CREATE TABLE coupons (
|
||||||
id uuid primary key,
|
id UUID PRIMARY KEY,
|
||||||
code text not null,
|
code TEXT NOT NULL,
|
||||||
discount smallint not null,
|
discount SMALLINT NOT NULL,
|
||||||
soft_deleted boolean default false )`,
|
soft_deleted BOOLEAN DEFAULT false )`,
|
||||||
`create unique index uq_code on coupons using btree(code) where not soft_deleted`
|
`CREATE UNIQUE INDEX uq_code ON coupons USING btree(code) WHERE NOT soft_deleted`
|
||||||
]
|
]
|
||||||
|
|
||||||
db.multi(sql, next)
|
db.multi(sql, next)
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,8 @@ const db = require('./db')
|
||||||
|
|
||||||
exports.up = function (next) {
|
exports.up = function (next) {
|
||||||
var sql = [
|
var sql = [
|
||||||
'alter table cash_in_txs add column discount smallint',
|
'ALTER TABLE cash_in_txs ADD COLUMN discount SMALLINT',
|
||||||
'alter table cash_out_txs add column discount smallint'
|
'ALTER TABLE cash_out_txs ADD COLUMN discount SMALLINT'
|
||||||
]
|
]
|
||||||
|
|
||||||
db.multi(sql, next)
|
db.multi(sql, next)
|
||||||
|
|
|
||||||
|
|
@ -2,10 +2,10 @@ const db = require('./db')
|
||||||
|
|
||||||
exports.up = function (next) {
|
exports.up = function (next) {
|
||||||
var sql = [
|
var sql = [
|
||||||
'alter table trades add column tx_in_id uuid unique',
|
'ALTER TABLE trades ADD COLUMN tx_in_id UUID UNIQUE',
|
||||||
'alter table trades add constraint fk_tx_in foreign key (tx_in_id) references cash_in_txs (id)',
|
'ALTER TABLE trades ADD CONSTRAINT fk_tx_in FOREIGN KEY (tx_in_id) REFERENCES cash_in_txs (id)',
|
||||||
'alter table trades add column tx_out_id uuid unique',
|
'ALTER TABLE trades ADD COLUMN tx_out_id UUID UNIQUE',
|
||||||
'alter table trades add constraint fk_tx_out foreign key (tx_in_id) references cash_out_txs (id)'
|
'ALTER TABLE trades ADD CONSTRAINT fk_tx_out FOREIGN KEY (tx_in_id) REFERENCES cash_out_txs (id)'
|
||||||
]
|
]
|
||||||
|
|
||||||
db.multi(sql, next)
|
db.multi(sql, next)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue