@ez4/pgmigration 0.41.0 → 0.43.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/library.cjs +102 -94
- package/dist/library.mjs +98 -91
- package/dist/main.cjs +151 -136
- package/dist/main.mjs +150 -133
- package/dist/queries/constraints.d.ts +5 -11
- package/dist/queries/indexes.d.ts +4 -3
- package/dist/types/query.d.ts +6 -0
- package/dist/utils/checks.d.ts +1 -0
- package/package.json +6 -6
package/dist/main.mjs
CHANGED
|
@@ -1,134 +1,151 @@
|
|
|
1
|
-
var
|
|
2
|
-
import{isTableMetadata as
|
|
3
|
-
|
|
4
|
-
(
|
|
5
|
-
|
|
6
|
-
"
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
select().rawColumn("1").where({
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
(
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
build()})}}return
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
i
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
i))
|
|
35
|
-
c
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
let
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
let{
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
let a=
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
break}}}return
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
"
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
c
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
d
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
p,
|
|
132
|
-
|
|
133
|
-
|
|
1
|
+
var re=Object.defineProperty;var c=(t,m)=>re(t,"name",{value:m,configurable:!0});import{SqlBuilder as L}from"@ez4/pgsql";import{deepEqual as W,deepCompareObject as oe,isAnyObject as G,toSnakeCase as J}from"@ez4/utils";
|
|
2
|
+
import{isTableMetadata as F}from"@ez4/pgclient/library";import{isAnySchema as H}from"@ez4/schema";var X=c((t,m)=>oe(t,m,{onSimilarName:c((y,h)=>{let g=new Set(J(y).split("_")),p=new Set(
|
|
3
|
+
J(h).split("_"));for(let f of p)if(f.length>1&&g.has(f))return!0;return!1},"onSi\
|
|
4
|
+
milarName"),onRename:c((y,h)=>!G(y)||!G(h)?!1:F(y)&&F(h)?se(y.schema,h.schema):H(
|
|
5
|
+
y)&&H(h)?ie(y,h):!1,"onRename")}),"getTableRepositoryChanges"),se=c((t,m)=>W(Object.
|
|
6
|
+
keys(t.properties),Object.keys(m.properties)),"canRenameTable"),ie=c((t,m)=>W(t,
|
|
7
|
+
m,{depth:1,include:{type:!0,definitions:!0,nullable:!0,format:!0}}),"canRenameCo\
|
|
8
|
+
lumn");import{isEnumSchema as Y,isScalarSchema as Z,SchemaType as $}from"@ez4/schema";import{
|
|
9
|
+
isNotNullish as ee}from"@ez4/utils";var R=c((t,m)=>{let[y]=t.select().rawColumn("1").from("pg_constraint").where({conname:t.
|
|
10
|
+
rawString(m)}).build();return y},"getCheckConstraintQuery"),V=c((t,m,y)=>{let[h]=t.
|
|
11
|
+
select().rawColumn("1").where({NOT:{exists:t.select().from(t.rawValue("informati\
|
|
12
|
+
on_schema.columns")).rawColumn("1").where({column_name:t.rawString(y),table_name:t.
|
|
13
|
+
rawString(m)})}}).build();return h},"getCheckColumnQuery"),K=c((t,m)=>{let[y]=t.
|
|
14
|
+
select().rawColumn("1").from("pg_constraint").where({convalidated:t.rawValue("tr\
|
|
15
|
+
ue"),conname:t.rawString(m)}).build();return y},"getCheckConstraintValidatedQuer\
|
|
16
|
+
y");import{toSnakeCase as ae}from"@ez4/utils";var A=c((t,m)=>`${D(t,m)}_pk`,"getPrimaryKeyName"),z=c((t,m)=>`${D(t,m)}_uk`,"ge\
|
|
17
|
+
tUniqueKeyName"),M=c((t,m)=>`${D(t,m)}_sk`,"getSecondaryKeyName"),j=c((t,m)=>`${D(
|
|
18
|
+
t,m)}_fk`,"getRelationName"),N=c((t,m)=>`${D(t,m)}_ck`,"getConstraintName"),D=c(
|
|
19
|
+
(t,m)=>`${t}_${ae(m.replaceAll(":","_"))}`,"getName");var v;(r=>{r.prepareCreate=c((e,n,d)=>{let a={constraints:[],validations:[]};for(let i in d){
|
|
20
|
+
let o=d[i];if(Y(o)||Z(o)&&ee(o.definitions?.value)){let u=N(n,i);a.constraints.push(
|
|
21
|
+
{check:R(e,u),query:s(e,n,u,i,o).build()}),a.validations.push({check:K(e,u),query:l(
|
|
22
|
+
e,n,u).build(),name:u})}}return a},"prepareCreate"),r.prepareUpdate=c((e,n,d,a,i)=>{
|
|
23
|
+
let o={constraints:[],validations:[]};for(let u in i){let{update:S,create:x,remove:q}=i[u];
|
|
24
|
+
if(q||S){let C=a.properties[u];if(p(C)){let b=N(n,u);o.constraints.push({query:f(
|
|
25
|
+
e,n,b).build()})}}if(x||S){let C=d.properties[u];if(p(C)){let b=N(n,u);o.constraints.
|
|
26
|
+
push({check:R(e,b),query:s(e,n,b,u,C).build()}),o.validations.push({check:K(e,b),
|
|
27
|
+
query:l(e,n,b).build(),name:b})}}}return o},"prepareUpdate"),r.prepareRenameTable=
|
|
28
|
+
c((e,n,d,a)=>{let i=[];for(let o in a){let u=a[o];if(p(u)){let S=N(n,o),x=N(d,o),
|
|
29
|
+
q=e.table(d).alter().existing().constraint(S).rename(x);i.push({check:R(e,x),query:q.
|
|
30
|
+
build()})}}return i},"prepareRenameTable"),r.prepareRenameColumns=c((e,n,d,a)=>{
|
|
31
|
+
let i=[];for(let o in a){let u=a[o],S=d[u];if(p(S)){let x=N(n,o),q=N(n,u),C=e.table(
|
|
32
|
+
n).alter().existing().constraint(x).rename(q);i.push({check:R(e,q),query:C.build()})}}
|
|
33
|
+
return i},"prepareRenameColumns"),r.prepareDelete=c((e,n,d)=>{let a=[];for(let i in d){
|
|
34
|
+
let o=d[i];if(p(o)){let u=N(n,i);a.push({query:f(e,n,u).build()})}}return a},"pr\
|
|
35
|
+
epareDelete");let p=c(e=>Y(e)||Z(e)&&ee(e.definitions?.value),"isConstrainedSche\
|
|
36
|
+
ma"),f=c((e,n,d)=>e.table(n).alter().existing().constraint(d).drop().existing(),
|
|
37
|
+
"getDeleteQuery"),l=c((e,n,d)=>e.table(n).alter().existing().constraint(d).validate(),
|
|
38
|
+
"getValidationQuery"),s=c((e,n,d,a,i)=>{let o=e.table(n).alter().existing().constraint(
|
|
39
|
+
d);switch(i.type){case $.Enum:{let u=i.options.map(({value:x})=>`${x}`);o.check(
|
|
40
|
+
{[a]:{isIn:u}}).validate(!1);break}case $.Boolean:case $.Number:case $.String:{o.
|
|
41
|
+
check({[a]:{equal:i.definitions?.value}}).validate(!1);break}}return o},"getCrea\
|
|
42
|
+
teQuery")})(v||={});import{getTableName as ce}from"@ez4/pgclient/library";import{isNullishSchema as me}from"@ez4/schema";
|
|
43
|
+
import{Index as te}from"@ez4/database";var O;(l=>{l.prepareCreate=c((s,r,e,n)=>{let d=[];for(let a in n){let i=n[a];if(g(
|
|
44
|
+
i))continue;let{[i.targetColumn]:o}=e.properties,u=j(r,a),S=!!me(o);d.push({check:R(
|
|
45
|
+
s,u),query:f(s,r,u,i,S).build()})}return d},"prepareCreate"),l.prepareUpdate=c((s,r,e,n)=>{
|
|
46
|
+
let d=[];for(let a in e){let i=e[a];if(g(i))continue;let o=n[i.targetColumn]?.update,
|
|
47
|
+
u=o?.optional??o?.nullable;if(u===void 0)continue;let S=j(r,a);d.push({query:p(s,
|
|
48
|
+
r,S).build()},{query:f(s,r,S,i,u).build()})}return d},"prepareUpdate"),l.prepareRename=
|
|
49
|
+
c((s,r,e,n)=>{let d=[];for(let a in n){let i=n[a];if(g(i))continue;let o=j(r,a),
|
|
50
|
+
u=j(e,a),S=s.table(e).alter().existing().constraint(o).rename(u);d.push({check:R(
|
|
51
|
+
s,u),query:S.build()})}return d},"prepareRename"),l.prepareDelete=c((s,r,e)=>{let n=[];
|
|
52
|
+
for(let d in e){let a=e[d];if(g(a))continue;let i=j(r,d);n.push({query:p(s,r,i).
|
|
53
|
+
build()})}return n},"prepareDelete");let g=c(s=>{let{sourceIndex:r,targetIndex:e}=s;
|
|
54
|
+
return!r||r===te.Secondary||e===te.Primary},"isNotRealRelation"),p=c((s,r,e)=>s.
|
|
55
|
+
table(r).alter().existing().constraint(e).drop().existing(),"getDeleteQuery"),f=c(
|
|
56
|
+
(s,r,e,n,d)=>{let{sourceTable:a,sourceColumn:i,targetColumn:o}=n,u=ce(a),S=s.table(
|
|
57
|
+
r).alter().existing().constraint(e),x=S.foreign(o,u,[i]).validate(!1);return d?x.
|
|
58
|
+
delete().null():x.delete().cascade(),x.update().cascade(),S},"getCreateQuery")})(
|
|
59
|
+
O||={});import{SchemaType as E}from"@ez4/schema";import{Index as w}from"@ez4/database";var B;(f=>{f.prepareCreate=c((l,s,r,e)=>{let n={constraints:[],validations:[],indexes:[]};
|
|
60
|
+
for(let d in e){let{columns:a,type:i,name:o}=e[d];switch(i){default:throw new Error(
|
|
61
|
+
"Unsupported index type.");case w.Primary:{let u=A(s,o);n.constraints.push({check:R(
|
|
62
|
+
l,u),query:l.table(s).alter().existing().constraint(u).primary(a).build()});break}case w.
|
|
63
|
+
Unique:{let u=z(s,o),S=p(a,r);n.indexes.push({query:l.index(u).create(s,a).type(
|
|
64
|
+
S).unique().concurrent().missing().build()}),n.validations.push({query:(0,f.getValidationQuery)(
|
|
65
|
+
l,u),name:u});break}case w.Secondary:{let u=M(s,o),S=p(a,r);n.indexes.push({query:l.
|
|
66
|
+
index(u).create(s,a).type(S).concurrent().missing().build()}),n.validations.push(
|
|
67
|
+
{query:(0,f.getValidationQuery)(l,u),name:u});break}}}return n},"prepareCreate"),
|
|
68
|
+
f.prepareUpdate=c((l,s,r,e,n,d)=>{let a={constraints:[],validations:[],indexes:[]};
|
|
69
|
+
for(let i in d){let{update:o,create:u,remove:S}=d[i];if(S||o){let x=(0,f.prepareDelete)(
|
|
70
|
+
l,s,{[i]:e[i]});a.constraints.push(...x.constraints),a.indexes.push(...x.indexes)}
|
|
71
|
+
if(u||o){let x=(0,f.prepareCreate)(l,s,r,{[i]:n[i]});a.constraints.push(...x.constraints),
|
|
72
|
+
a.indexes.push(...x.indexes)}}return a},"prepareUpdate"),f.prepareRename=c((l,s,r,e)=>{
|
|
73
|
+
let n={validations:[],constraints:[],indexes:[]};for(let d in e){let{type:a,name:i}=e[d];
|
|
74
|
+
switch(a){default:throw new Error("Unsupported index type.");case w.Primary:{let o=A(
|
|
75
|
+
s,i),u=A(r,i);n.constraints.push({check:R(l,u),query:l.table(r).alter().existing().
|
|
76
|
+
constraint(o).rename(u).build()});break}case w.Unique:{let o=z(s,i),u=z(r,i);n.indexes.
|
|
77
|
+
push({query:l.index(o).rename(u).existing().build()});break}case w.Secondary:{let o=M(
|
|
78
|
+
s,i),u=M(r,i);n.indexes.push({query:l.index(o).rename(u).existing().build()});break}}}
|
|
79
|
+
return n},"prepareRename"),f.prepareDelete=c((l,s,r)=>{let e={validations:[],constraints:[],
|
|
80
|
+
indexes:[]};for(let n in r){let{type:d,name:a}=r[n];switch(d){default:throw new Error(
|
|
81
|
+
"Unsupported index type.");case w.Primary:{let i=A(s,a),o=l.table(s).alter().existing().
|
|
82
|
+
constraint(i).drop().existing();e.constraints.push({query:o.build()});break}case w.
|
|
83
|
+
Unique:{let i=z(s,a),o=l.index(i).drop().existing().concurrent();e.indexes.push(
|
|
84
|
+
{query:o.build()});break}case w.Secondary:{let i=M(s,a),o=l.index(i).drop().existing().
|
|
85
|
+
concurrent();e.indexes.push({query:o.build()});break}}}return e},"prepareDelete"),
|
|
86
|
+
f.getValidationQuery=c((l,s)=>{let[r]=l.select().rawColumn("1").from("pg_index").
|
|
87
|
+
where({indexrelid:l.rawValue(`${l.rawString(s).build()}::regclass`),indisvalid:l.
|
|
88
|
+
rawValue("false"),indisready:l.rawValue("true")}).build();return r},"getValidati\
|
|
89
|
+
onQuery");let p=c((l,s)=>{if(l.length===1){let[r]=l;switch(s.properties[r]?.type){case E.
|
|
90
|
+
Object:case E.Union:case E.Array:case E.Tuple:return"GIN"}}return"BTREE"},"getIn\
|
|
91
|
+
dexType")})(B||={});import{Index as ne}from"@ez4/database";import{isArraySchema as pe,isEnumSchema as ue,isObjectSchema as le,isScalarSchema as de,
|
|
92
|
+
isStringSchema as ge,isTupleSchema as fe,SchemaType as k}from"@ez4/schema";import{
|
|
93
|
+
isAnyNumber as ye}from"@ez4/utils";var U=c(t=>!!(t.nullable||t.optional),"isOptionalColumn"),T=c((t,m)=>{if(de(t)||
|
|
94
|
+
le(t)||pe(t)||fe(t)){let{definitions:y}=t;switch(typeof y?.default){case"boolean":case"\
|
|
95
|
+
number":return`${y.default}`;case"string":return`'${y.default}'`;case"object":return`\
|
|
96
|
+
'${JSON.stringify(y.default)}'`}}if(ue(t)){let{definitions:y}=t;if(y?.default)return`\
|
|
97
|
+
'${y.default}'`}if(ge(t)&&m)switch(t.format){case"date-time":case"date":case"tim\
|
|
98
|
+
e":return"now()";case"uuid":return"gen_random_uuid()"}if(U(t))return"null"},"get\
|
|
99
|
+
ColumnDefault"),_=c((t,m)=>{switch(t.type){case k.Array:case k.Object:case k.Reference:case k.
|
|
100
|
+
Union:case k.Tuple:return"jsonb";case k.Boolean:return"boolean";case k.Enum:return"\
|
|
101
|
+
text";case k.Number:return he(t,m);case k.String:return xe(t)}},"getColumnType"),
|
|
102
|
+
he=c((t,m)=>t.format==="integer"?m?"bigserial":"bigint":"decimal","getColumNumbe\
|
|
103
|
+
rType"),xe=c(t=>{switch(t.format){case"uuid":case"time":case"date":return t.format;case"\
|
|
104
|
+
date-time":return"timestamptz";default:let m=t.definitions?.maxLength;return ye(
|
|
105
|
+
m)?`varchar(${m})`:"text"}},"getColumnTextType");var I;(g=>(g.prepareCreate=c((p,f,l,s)=>{let r=p.table(f).alter().existing();for(let e in s){
|
|
106
|
+
let n=s[e],a=l[e]?.type===ne.Primary,i=!U(n),o=_(n,a),u=T(n,a);r.add(e,o,i,u).missing()}
|
|
107
|
+
return{query:r.build()}},"prepareCreate"),g.prepareUpdate=c((p,f,l,s,r)=>{let e=[];
|
|
108
|
+
for(let n in r){let{create:d,update:a,nested:i,remove:o}=r[n],u=l.properties[n],
|
|
109
|
+
x=s[n]?.type===ne.Primary,q=p.table(f).alter().existing().column(n);if(d){let C=d.
|
|
110
|
+
definitions?.default,b=d?.nullable;C!==void 0&&q.default(T(u,x)),!x&&b!==void 0&&
|
|
111
|
+
q.optional(b)}if(a||i){let C=i?.definitions?.update?.default,b=a?.nullable;a?.type!==
|
|
112
|
+
void 0&&q.type(_(u,x)),C!==void 0&&q.default(T(u,x)),!x&&b!==void 0&&q.optional(
|
|
113
|
+
b)}if(o){let C=o.definitions?.default,b=o?.nullable;C!==void 0&&q.default(null),
|
|
114
|
+
!x&&b!==void 0&&q.optional(b)}q.empty||e.push({check:V(p,f,n),query:q.build()})}
|
|
115
|
+
return e},"prepareUpdate"),g.prepareRename=c((p,f,l)=>{let s=[];for(let r in l){
|
|
116
|
+
let e=l[r],n=p.table(f).alter().existing().rename(r,e);s.push({check:V(p,f,r),query:n.
|
|
117
|
+
build()})}return s},"prepareRename"),g.prepareDelete=c((p,f,l)=>{let s=p.table(f).
|
|
118
|
+
alter().existing();for(let r in l)s.drop(r).existing();return{query:s.build()}},
|
|
119
|
+
"prepareDelete")))(I||={});import{Index as Se}from"@ez4/database";var Q;(h=>(h.prepareCreate=c((g,p,f,l)=>{let s=g.table(p).create().missing();for(let r in f.
|
|
120
|
+
properties){let e=f.properties[r],d=l[r]?.type===Se.Primary,a=!U(e),i=_(e,d),o=T(
|
|
121
|
+
e,d);s.column(r,i,a,o).missing()}return{query:s.build()}},"prepareCreate"),h.prepareRename=
|
|
122
|
+
c((g,p,f)=>({query:g.table(p).rename(f).existing().build()}),"prepareRename"),h.
|
|
123
|
+
prepareDelete=c((g,p)=>({query:g.table(p).drop().existing().cascade().build()}),
|
|
124
|
+
"prepareDelete")))(Q||={});var qe=c(t=>{let m=new L,y={tables:[],constraints:[],validations:[],relations:[],
|
|
125
|
+
indexes:[]};for(let h in t){let{name:g,schema:p,indexes:f,relations:l}=t[h];y.tables.
|
|
126
|
+
push(Q.prepareCreate(m,g,p,f)),y.relations.push(...O.prepareCreate(m,g,p,l)),P(y,
|
|
127
|
+
v.prepareCreate(m,g,p.properties)),P(y,B.prepareCreate(m,g,p,f))}return y},"getC\
|
|
128
|
+
reateQueries"),St=c((t,m)=>{let y=X(t,m),h=new L,g={tables:[],constraints:[],validations:[],
|
|
129
|
+
relations:[],indexes:[]};if(y.create&&P(g,qe(y.create)),y.rename)for(let p in y.
|
|
130
|
+
rename){let f=y.rename[p],l=t[f].indexes,s=t[f].relations,r=t[f].schema;g.tables.
|
|
131
|
+
push(Q.prepareRename(h,p,f)),g.constraints.push(...v.prepareRenameTable(h,p,f,r.
|
|
132
|
+
properties)),g.relations.push(...O.prepareRename(h,p,f,s)),P(g,B.prepareRename(h,
|
|
133
|
+
p,f,l))}if(y.nested)for(let p in y.nested){let{nested:f}=y.nested[p];if(!f)continue;
|
|
134
|
+
let{schema:l,relations:s,indexes:r}=f,e=l?.nested?.properties,n=t[p].relations,d=m[p].
|
|
135
|
+
indexes,a=t[p].indexes,i=m[p].schema,o=t[p].schema;e?.create&&(g.tables.push(I.prepareCreate(
|
|
136
|
+
h,p,a,e.create)),P(g,v.prepareCreate(h,p,e.create))),e?.nested&&(g.tables.push(...I.
|
|
137
|
+
prepareUpdate(h,p,o,a,e.nested)),P(g,v.prepareUpdate(h,p,o,i,e.nested)),g.relations.
|
|
138
|
+
push(...O.prepareUpdate(h,p,n,e.nested))),e?.rename&&(g.tables.push(...I.prepareRename(
|
|
139
|
+
h,p,e.rename)),g.constraints.push(...v.prepareRenameColumns(h,p,o.properties,e.rename))),
|
|
140
|
+
e?.remove&&(g.tables.push(I.prepareDelete(h,p,e.remove)),g.constraints.push(...v.
|
|
141
|
+
prepareDelete(h,p,e.remove))),r?.create&&P(g,B.prepareCreate(h,p,o,r.create)),r?.
|
|
142
|
+
nested&&P(g,B.prepareUpdate(h,p,o,d,a,r.nested)),r?.remove&&P(g,B.prepareDelete(
|
|
143
|
+
h,p,r.remove)),s?.create&&g.relations.push(...O.prepareCreate(h,p,o,s.create)),s?.
|
|
144
|
+
remove&&g.relations.push(...O.prepareDelete(h,p,s.remove))}return y.remove&&P(g,
|
|
145
|
+
be(y.remove)),g},"getUpdateQueries"),be=c(t=>{let m=new L,y={tables:[],constraints:[],
|
|
146
|
+
validations:[],relations:[],indexes:[]};for(let h in t){let{name:g}=t[h];y.tables.
|
|
147
|
+
push(Q.prepareDelete(m,g))}return y},"getDeleteQueries"),P=c((t,m)=>{m.tables&&t.
|
|
148
|
+
tables.push(...m.tables),m.constraints&&t.constraints.push(...m.constraints),m.validations&&
|
|
149
|
+
t.validations.push(...m.validations),m.relations&&t.relations.push(...m.relations),
|
|
150
|
+
m.indexes&&t.indexes.push(...m.indexes)},"combineQueries");export{qe as getCreateQueries,be as getDeleteQueries,St as getUpdateQueries};
|
|
134
151
|
//# sourceMappingURL=main.mjs.map
|
|
@@ -1,18 +1,11 @@
|
|
|
1
1
|
import type { AnySchema, ObjectSchema, ObjectSchemaProperties } from '@ez4/schema';
|
|
2
2
|
import type { ObjectComparison } from '@ez4/utils';
|
|
3
3
|
import type { SqlBuilder } from '@ez4/pgsql';
|
|
4
|
+
import type { PgMigrationQueries } from '../types/query';
|
|
5
|
+
type ConstraintMigrationQueries = Pick<PgMigrationQueries, 'constraints' | 'validations'>;
|
|
4
6
|
export declare namespace ConstraintQuery {
|
|
5
|
-
const prepareCreate: (builder: SqlBuilder, table: string, columns: Record<string, AnySchema>) =>
|
|
6
|
-
|
|
7
|
-
query: string;
|
|
8
|
-
}[];
|
|
9
|
-
const prepareUpdate: (builder: SqlBuilder, table: string, targetSchema: ObjectSchema, sourceSchema: ObjectSchema, changes: Record<string, ObjectComparison>) => ({
|
|
10
|
-
query: string;
|
|
11
|
-
check?: undefined;
|
|
12
|
-
} | {
|
|
13
|
-
check: string;
|
|
14
|
-
query: string;
|
|
15
|
-
})[];
|
|
7
|
+
const prepareCreate: (builder: SqlBuilder, table: string, columns: Record<string, AnySchema>) => ConstraintMigrationQueries;
|
|
8
|
+
const prepareUpdate: (builder: SqlBuilder, table: string, targetSchema: ObjectSchema, sourceSchema: ObjectSchema, changes: Record<string, ObjectComparison>) => ConstraintMigrationQueries;
|
|
16
9
|
const prepareRenameTable: (builder: SqlBuilder, fromTable: string, toTable: string, columns: Record<string, AnySchema>) => {
|
|
17
10
|
check: string;
|
|
18
11
|
query: string;
|
|
@@ -25,3 +18,4 @@ export declare namespace ConstraintQuery {
|
|
|
25
18
|
query: string;
|
|
26
19
|
}[];
|
|
27
20
|
}
|
|
21
|
+
export {};
|
|
@@ -3,11 +3,12 @@ import type { ObjectComparison } from '@ez4/utils';
|
|
|
3
3
|
import type { ObjectSchema } from '@ez4/schema';
|
|
4
4
|
import type { SqlBuilder } from '@ez4/pgsql';
|
|
5
5
|
import type { PgMigrationQueries } from '../types/query';
|
|
6
|
-
type IndexMigrationQueries = Pick<PgMigrationQueries, 'constraints' | 'indexes'>;
|
|
6
|
+
type IndexMigrationQueries = Pick<PgMigrationQueries, 'constraints' | 'validations' | 'indexes'>;
|
|
7
7
|
export declare namespace IndexQueries {
|
|
8
|
-
const prepareCreate: (builder: SqlBuilder, table: string, schema: ObjectSchema, indexes: PgIndexRepository
|
|
9
|
-
const prepareUpdate: (builder: SqlBuilder, table: string, schema: ObjectSchema, sourceIndexes: PgIndexRepository, targetIndexes: PgIndexRepository, changes: Record<string, ObjectComparison
|
|
8
|
+
const prepareCreate: (builder: SqlBuilder, table: string, schema: ObjectSchema, indexes: PgIndexRepository) => IndexMigrationQueries;
|
|
9
|
+
const prepareUpdate: (builder: SqlBuilder, table: string, schema: ObjectSchema, sourceIndexes: PgIndexRepository, targetIndexes: PgIndexRepository, changes: Record<string, ObjectComparison>) => IndexMigrationQueries;
|
|
10
10
|
const prepareRename: (builder: SqlBuilder, fromTable: string, toTable: string, indexes: PgIndexRepository) => IndexMigrationQueries;
|
|
11
11
|
const prepareDelete: (builder: SqlBuilder, table: string, indexes: PgIndexRepository) => IndexMigrationQueries;
|
|
12
|
+
const getValidationQuery: (builder: SqlBuilder, name: string) => string;
|
|
12
13
|
}
|
|
13
14
|
export {};
|
package/dist/types/query.d.ts
CHANGED
|
@@ -2,9 +2,15 @@ export type PgMigrationStatement = {
|
|
|
2
2
|
check?: string;
|
|
3
3
|
query: string;
|
|
4
4
|
};
|
|
5
|
+
export type PgValidationStatement = {
|
|
6
|
+
name: string;
|
|
7
|
+
check?: string;
|
|
8
|
+
query: string;
|
|
9
|
+
};
|
|
5
10
|
export type PgMigrationQueries = {
|
|
6
11
|
tables: PgMigrationStatement[];
|
|
7
12
|
constraints: PgMigrationStatement[];
|
|
13
|
+
validations: PgValidationStatement[];
|
|
8
14
|
relations: PgMigrationStatement[];
|
|
9
15
|
indexes: PgMigrationStatement[];
|
|
10
16
|
};
|
package/dist/utils/checks.d.ts
CHANGED
|
@@ -2,3 +2,4 @@ import type { SqlBuilder } from '@ez4/pgsql';
|
|
|
2
2
|
export declare const getCheckDatabaseQuery: (builder: SqlBuilder, database: string) => string;
|
|
3
3
|
export declare const getCheckConstraintQuery: (builder: SqlBuilder, name: string) => string;
|
|
4
4
|
export declare const getCheckColumnQuery: (builder: SqlBuilder, table: string, column: string) => string;
|
|
5
|
+
export declare const getCheckConstraintValidatedQuery: (builder: SqlBuilder, name: string) => string;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ez4/pgmigration",
|
|
3
3
|
"description": "EZ4: A PostgreSQL migration library",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.43.0",
|
|
5
5
|
"author": "Silas B.",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"type": "module",
|
|
@@ -43,10 +43,10 @@
|
|
|
43
43
|
"live:publish": "npm run build && npm publish --access public"
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@ez4/database": "^0.
|
|
47
|
-
"@ez4/pgsql": "^0.
|
|
48
|
-
"@ez4/pgclient": "^0.
|
|
49
|
-
"@ez4/schema": "^0.
|
|
50
|
-
"@ez4/utils": "^0.
|
|
46
|
+
"@ez4/database": "^0.43.0",
|
|
47
|
+
"@ez4/pgsql": "^0.43.0",
|
|
48
|
+
"@ez4/pgclient": "^0.43.0",
|
|
49
|
+
"@ez4/schema": "^0.43.0",
|
|
50
|
+
"@ez4/utils": "^0.43.0"
|
|
51
51
|
}
|
|
52
52
|
}
|