@ez4/pgmigration 0.26.0 → 0.27.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 +87 -92
- package/dist/library.d.ts +7 -7
- package/dist/library.mjs +85 -87
- package/dist/main.cjs +128 -123
- package/dist/main.d.ts +1 -1
- package/dist/main.mjs +123 -118
- package/dist/queries/columns.d.ts +20 -0
- package/dist/queries/constraints.d.ts +27 -0
- package/dist/queries/database.d.ts +9 -0
- package/dist/queries/indexes.d.ts +11 -0
- package/dist/queries/relations.d.ts +18 -0
- package/dist/queries/tables.d.ts +14 -0
- package/dist/service/queries.d.ts +1 -1
- package/package.json +11 -13
- package/dist/common/columns.d.ts +0 -18
- package/dist/common/constraints.d.ts +0 -25
- package/dist/common/database.d.ts +0 -7
- package/dist/common/indexes.d.ts +0 -9
- package/dist/common/relations.d.ts +0 -16
- package/dist/common/tables.d.ts +0 -12
package/dist/main.mjs
CHANGED
|
@@ -1,120 +1,125 @@
|
|
|
1
|
-
var
|
|
2
|
-
isStringSchema as
|
|
3
|
-
isAnyNumber as
|
|
4
|
-
|
|
5
|
-
number":return`${
|
|
6
|
-
'${JSON.stringify(
|
|
7
|
-
'${
|
|
8
|
-
e":return"now()";case"uuid":return"gen_random_uuid()"}if(
|
|
9
|
-
ColumnDefault"),
|
|
10
|
-
Union:case
|
|
11
|
-
text";case
|
|
12
|
-
|
|
13
|
-
rType"),
|
|
14
|
-
date-time":return"timestamptz";default:let
|
|
15
|
-
|
|
16
|
-
let
|
|
17
|
-
r,
|
|
18
|
-
query:
|
|
19
|
-
query:
|
|
20
|
-
|
|
1
|
+
var X=Object.defineProperty;var m=(e,c)=>X(e,"name",{value:c,configurable:!0});import{SqlBuilder as L}from"@ez4/pgsql";import{Index as ae}from"@ez4/database";import{isArraySchema as Y,isEnumSchema as Z,isObjectSchema as ee,isScalarSchema as te,
|
|
2
|
+
isStringSchema as re,isTupleSchema as ne,SchemaType as C}from"@ez4/schema";import{
|
|
3
|
+
isAnyNumber as oe}from"@ez4/utils";var A=m(e=>!!(e.nullable||e.optional),"isOptionalColumn"),z=m((e,c)=>{if(te(e)||
|
|
4
|
+
ee(e)||Y(e)||ne(e)){let{definitions:d}=e;switch(typeof d?.default){case"boolean":case"\
|
|
5
|
+
number":return`${d.default}`;case"string":return`'${d.default}'`;case"object":return`\
|
|
6
|
+
'${JSON.stringify(d.default)}'`}}if(Z(e)){let{definitions:d}=e;if(d?.default)return`\
|
|
7
|
+
'${d.default}'`}if(re(e)&&c)switch(e.format){case"date-time":case"date":case"tim\
|
|
8
|
+
e":return"now()";case"uuid":return"gen_random_uuid()"}if(A(e))return"null"},"get\
|
|
9
|
+
ColumnDefault"),D=m((e,c)=>{switch(e.type){case C.Array:case C.Object:case C.Reference:case C.
|
|
10
|
+
Union:case C.Tuple:return"jsonb";case C.Boolean:return"boolean";case C.Enum:return"\
|
|
11
|
+
text";case C.Number:return se(e,c);case C.String:return ie(e)}},"getColumnType"),
|
|
12
|
+
se=m((e,c)=>e.format==="integer"?c?"bigserial":"bigint":"decimal","getColumNumbe\
|
|
13
|
+
rType"),ie=m(e=>{switch(e.format){case"uuid":case"time":case"date":return e.format;case"\
|
|
14
|
+
date-time":return"timestamptz";default:let c=e.definitions?.maxLength;return oe(
|
|
15
|
+
c)?`varchar(${c})`:"text"}},"getColumnTextType");var U;(y=>(y.prepareCreate=m((g,n,p,u)=>{let o=g.table(n).create().missing();for(let t in p.
|
|
16
|
+
properties){let r=p.properties[t],a=u[t]?.type===ae.Primary,l=!A(r),i=D(r,a),f=z(
|
|
17
|
+
r,a);o.column(t,i,l,f).missing()}return{query:o.build()}},"prepareCreate"),y.prepareRename=
|
|
18
|
+
m((g,n,p)=>({query:g.table(n).rename(p).existing().build()}),"prepareRename"),y.
|
|
19
|
+
prepareDelete=m((g,n)=>({query:g.table(n).drop().existing().cascade().build()}),
|
|
20
|
+
"prepareDelete")))(U||={});import{Index as V}from"@ez4/database";var x=m((e,c)=>{let[d]=e.select().rawColumn("1").from("pg_constraint").where({conname:e.
|
|
21
|
+
rawString(c)}).build();return d},"getCheckConstraintQuery"),K=m((e,c,d)=>{let[y]=e.
|
|
21
22
|
select().rawColumn("1").from("information_schema.columns").where({column_name:e.
|
|
22
|
-
rawString(
|
|
23
|
-
|
|
24
|
-
query:
|
|
25
|
-
let{update:
|
|
26
|
-
update?.default,
|
|
27
|
-
column(
|
|
28
|
-
P(
|
|
29
|
-
|
|
30
|
-
existing().rename(
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
t,i);
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
s
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
import{
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
"
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
i)
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
indexes:
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
(
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
let{
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
u?.nested
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
remove&&
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
23
|
+
rawString(d),table_name:e.rawString(c)}).build();return y},"getCheckColumnQuery");var I;(g=>(g.prepareCreate=m((n,p,u,o)=>{let t=n.table(p).alter().existing();for(let r in o){
|
|
24
|
+
let s=o[r],l=u[r]?.type===V.Primary,i=!A(s),f=D(s,l),h=z(s,l);t.add(r,f,i,h).missing()}
|
|
25
|
+
return{query:t.build()}},"prepareCreate"),g.prepareUpdate=m((n,p,u,o,t)=>{let r=[];
|
|
26
|
+
for(let s in t){let{update:a,nested:l}=t[s],i=u.properties[s],h=o[s]?.type===V.Primary,
|
|
27
|
+
P=l?.definitions?.update?.default,S=a?.optional??a?.nullable,b=a?.type,N=n.table(
|
|
28
|
+
p).alter().existing().column(s);b!==void 0&&N.type(D(i,h)),S!==void 0&&N.optional(
|
|
29
|
+
S),P!==void 0&&N.default(z(i,h)),!N.empty&&r.push({check:K(n,p,s),query:N.build()})}
|
|
30
|
+
return r},"prepareUpdate"),g.prepareRename=m((n,p,u)=>{let o=[];for(let t in u){
|
|
31
|
+
let r=u[t],s=n.table(p).alter().existing().rename(t,r);o.push({check:K(n,p,t),query:s.
|
|
32
|
+
build()})}return o},"prepareRename"),g.prepareDelete=m((n,p,u)=>{let o=n.table(p).
|
|
33
|
+
alter().existing();for(let t in u)o.drop(t).existing();return{query:o.build()}},
|
|
34
|
+
"prepareDelete")))(I||={});import{isEnumSchema as k}from"@ez4/schema";import{toSnakeCase as ce}from"@ez4/utils";var M=m((e,c)=>`${$(e,c)}_pk`,"getPrimaryKeyName"),_=m((e,c)=>`${$(e,c)}_uk`,"ge\
|
|
35
|
+
tUniqueKeyName"),Q=m((e,c)=>`${$(e,c)}_sk`,"getSecondaryKeyName"),j=m((e,c)=>`${$(
|
|
36
|
+
e,c)}_fk`,"getRelationName"),q=m((e,c)=>`${$(e,c)}_ck`,"getConstraintName"),$=m(
|
|
37
|
+
(e,c)=>`${e}_${ce(c.replaceAll(":","_"))}`,"getName");var O;(u=>{u.prepareCreate=m((o,t,r)=>{let s=[];for(let a in r){let l=r[a];if(!k(
|
|
38
|
+
l))continue;let i=q(t,a);s.push({check:x(o,i),query:p(o,t,i,a,l.options).build()})}
|
|
39
|
+
return s},"prepareCreate"),u.prepareUpdate=m((o,t,r,s,a)=>{let l=[];for(let i in a){
|
|
40
|
+
let{update:f,create:h,remove:P}=a[i];if(P){let S=s.properties[i];if(k(S)){let b=q(
|
|
41
|
+
t,i);l.push({query:n(o,t,b).build()})}}if(f){let S=s.properties[i],b=r.properties[i];
|
|
42
|
+
if(k(S)&&k(b)){let N=q(t,i);l.push({query:n(o,t,N).build()},{query:p(o,t,N,i,b.options).
|
|
43
|
+
build()})}}if(h){let S=r.properties[i];if(k(S)){let b=q(t,i);l.push({check:x(o,b),
|
|
44
|
+
query:p(o,t,b,i,S.options).build()})}}}return l},"prepareUpdate"),u.prepareRenameTable=
|
|
45
|
+
m((o,t,r,s)=>{let a=[];for(let l in s){let i=s[l];if(!k(i))continue;let f=q(t,l),
|
|
46
|
+
h=q(r,l),P=o.table(r).alter().existing().constraint(f).rename(h);a.push({check:x(
|
|
47
|
+
o,h),query:P.build()})}return a},"prepareRenameTable"),u.prepareRenameColumns=m(
|
|
48
|
+
(o,t,r,s)=>{let a=[];for(let l in s){let i=s[l],f=r[i];if(!k(f))continue;let h=q(
|
|
49
|
+
t,l),P=q(t,i),S=o.table(t).alter().existing().constraint(h).rename(P);a.push({check:x(
|
|
50
|
+
o,P),query:S.build()})}return a},"prepareRenameColumns"),u.prepareDelete=m((o,t,r)=>{
|
|
51
|
+
let s=[];for(let a in r){let l=r[a];if(!k(l))continue;let i=q(t,a);s.push({query:n(
|
|
52
|
+
o,t,i).build()})}return s},"prepareDelete");let n=m((o,t,r)=>o.table(t).alter().
|
|
53
|
+
existing().constraint(r).drop().existing(),"getDeleteQuery"),p=m((o,t,r,s,a)=>{let l=a.
|
|
54
|
+
map(({value:i})=>`${i}`);return o.table(t).alter().existing().constraint(r).check(
|
|
55
|
+
{[s]:{isIn:l}})},"getCreateQuery")})(O||={});import{getTableName as pe}from"@ez4/pgclient/library";import{IsNullishSchema as me}from"@ez4/schema";
|
|
56
|
+
import{Index as v}from"@ez4/database";var B;(p=>{p.prepareCreate=m((u,o,t,r)=>{let s=[];for(let a in r){let l=r[a];if(l.
|
|
57
|
+
targetIndex===v.Primary)continue;let{[l.targetColumn]:i}=t.properties,f=j(o,a),h=!!me(
|
|
58
|
+
i);s.push({check:x(u,f),query:n(u,o,f,l,h).build()})}return s},"prepareCreate"),
|
|
59
|
+
p.prepareUpdate=m((u,o,t,r)=>{let s=[];for(let a in t){let l=t[a];if(l.targetIndex===
|
|
60
|
+
v.Primary)continue;let i=r[l.targetColumn]?.update,f=i?.optional??i?.nullable;if(f===
|
|
61
|
+
void 0)continue;let h=j(o,a);s.push({query:g(u,o,h).build()},{query:n(u,o,h,l,f).
|
|
62
|
+
build()})}return s},"prepareUpdate"),p.prepareRename=m((u,o,t,r)=>{let s=[];for(let a in r){
|
|
63
|
+
if(r[a].targetIndex===v.Primary)continue;let i=j(o,a),f=j(t,a),h=u.table(t).alter().
|
|
64
|
+
existing().constraint(i).rename(f);s.push({check:x(u,f),query:h.build()})}return s},
|
|
65
|
+
"prepareRename"),p.prepareDelete=m((u,o,t)=>{let r=[];for(let s in t){if(t[s].targetIndex===
|
|
66
|
+
v.Primary)continue;let l=j(o,s);r.push({query:g(u,o,l).build()})}return r},"prep\
|
|
67
|
+
areDelete");let g=m((u,o,t)=>u.table(o).alter().existing().constraint(t).drop().
|
|
68
|
+
existing(),"getDeleteQuery"),n=m((u,o,t,r,s)=>{let{sourceTable:a,sourceColumn:l,
|
|
69
|
+
targetColumn:i}=r,f=pe(a),h=u.table(o).alter().existing().constraint(t).foreign(
|
|
70
|
+
i,f,[l]);return s?h.delete().null():h.delete().cascade(),h.update().cascade(),h},
|
|
71
|
+
"getCreateQuery")})(B||={});import{SchemaType as E}from"@ez4/schema";import{Index as R}from"@ez4/database";var w;(g=>{g.prepareCreate=m((n,p,u,o,t)=>{let r={constraints:[],indexes:[]};for(let s in o){
|
|
72
|
+
let{columns:a,type:l}=o[s];switch(l){default:throw new Error("Unsupported index \
|
|
73
|
+
type.");case R.Primary:{let i=M(p,s),f=n.table(p).alter().existing().constraint(
|
|
74
|
+
i).primary(a);r.constraints.push({check:x(n,i),query:f.build()});break}case R.Unique:{
|
|
75
|
+
let i=_(p,s),f=n.table(p).alter().existing().constraint(i).unique(a);r.constraints.
|
|
76
|
+
push({check:x(n,i),query:f.build()});break}case R.Secondary:{let i=Q(p,s),f=y(a,
|
|
77
|
+
u),h=n.index(i).create(p,a).type(f).missing();t&&h.concurrent(),r.indexes.push({
|
|
78
|
+
query:h.build()});break}}}return r},"prepareCreate"),g.prepareRename=m((n,p,u,o)=>{
|
|
79
|
+
let t={constraints:[],indexes:[]};for(let r in o){let{type:s}=o[r];switch(s){default:
|
|
80
|
+
throw new Error("Unsupported index type.");case R.Primary:{let a=M(p,r),l=M(u,r),
|
|
81
|
+
i=n.table(u).alter().existing().constraint(a).rename(l);t.constraints.push({check:x(
|
|
82
|
+
n,l),query:i.build()});break}case R.Unique:{let a=_(p,r),l=_(u,r),i=n.table(u).alter().
|
|
83
|
+
existing().constraint(a).rename(l);t.constraints.push({check:x(n,l),query:i.build()});
|
|
84
|
+
break}case R.Secondary:{let a=Q(p,r),l=Q(u,r),i=n.index(a).rename(l).existing();
|
|
85
|
+
t.indexes.push({query:i.build()});break}}}return t},"prepareRename"),g.prepareDelete=
|
|
86
|
+
m((n,p,u)=>{let o={constraints:[],indexes:[]};for(let t in u){let{type:r}=u[t];switch(r){default:
|
|
87
|
+
throw new Error("Unsupported index type.");case R.Primary:{let s=M(p,t),a=n.table(
|
|
88
|
+
p).alter().existing().constraint(s).drop().existing();o.constraints.push({query:a.
|
|
89
|
+
build()});break}case R.Unique:{let s=_(p,t),a=n.table(p).alter().existing().constraint(
|
|
90
|
+
s).drop().existing();o.constraints.push({query:a.build()});break}case R.Secondary:{
|
|
91
|
+
let s=Q(p,t),a=n.index(s).drop().existing().concurrent();o.indexes.push({query:a.
|
|
92
|
+
build()});break}}}return o},"prepareDelete");let y=m((n,p)=>{if(n.length===1){let[
|
|
93
|
+
u]=n;switch(p.properties[u]?.type){case E.Object:case E.Union:case E.Array:case E.
|
|
94
|
+
Tuple:return"GIN"}}return"BTREE"},"getIndexType")})(w||={});import{deepEqual as H,deepCompareObject as ue,isAnyObject as G}from"@ez4/utils";
|
|
95
|
+
import{isTableMetadata as J}from"@ez4/pgclient/library";import{isAnySchema as F}from"@ez4/schema";var W=m((e,c)=>ue(e,c,{onRename:m((d,y)=>!G(d)||!G(y)?!1:J(d)&&J(y)?le(d.schema,
|
|
96
|
+
y.schema):F(d)&&F(y)?ge(d,y):!1,"onRename")}),"getTableRepositoryChanges"),le=m(
|
|
97
|
+
(e,c)=>H(Object.keys(e.properties),Object.keys(c.properties)),"canRenameTable"),
|
|
98
|
+
ge=m((e,c)=>H(e,c,{depth:1,include:{type:!0,definitions:!0,nullable:!0,format:!0}}),
|
|
99
|
+
"canRenameColumn");var de=m(e=>{let c=new L,d={tables:[],constraints:[],relations:[],indexes:[]};for(let y in e){
|
|
100
|
+
let{name:g,schema:n,indexes:p,relations:u}=e[y];d.tables.push(U.prepareCreate(c,
|
|
101
|
+
g,n,p)),d.constraints.push(...O.prepareCreate(c,g,n.properties)),d.relations.push(
|
|
102
|
+
...B.prepareCreate(c,g,n,u)),T(d,w.prepareCreate(c,g,n,p,!1))}return d},"getCrea\
|
|
103
|
+
teQueries"),ut=m((e,c)=>{let d=W(e,c),y=new L,g={tables:[],constraints:[],relations:[],
|
|
104
|
+
indexes:[]};if(d.create&&T(g,de(d.create)),d.rename)for(let n in d.rename){let p=d.
|
|
105
|
+
rename[n],u=e[p].indexes,o=e[p].relations,t=e[p].schema;g.tables.push(U.prepareRename(
|
|
106
|
+
y,n,p)),g.constraints.push(...O.prepareRenameTable(y,n,p,t.properties)),g.relations.
|
|
107
|
+
push(...B.prepareRename(y,n,p,o)),T(g,w.prepareRename(y,n,p,u))}if(d.nested)for(let n in d.
|
|
108
|
+
nested){let{nested:p}=d.nested[n];if(!p)continue;let{schema:u,relations:o,indexes:t}=p,
|
|
109
|
+
r=u?.nested?.properties,s=e[n].indexes,a=e[n].relations,l=c[n].schema,i=e[n].schema;
|
|
110
|
+
r?.create&&(g.tables.push(I.prepareCreate(y,n,s,r.create)),g.constraints.push(...O.
|
|
111
|
+
prepareCreate(y,n,r.create))),r?.nested&&(g.tables.push(...I.prepareUpdate(y,n,i,
|
|
112
|
+
s,r.nested)),g.constraints.push(...O.prepareUpdate(y,n,i,l,r.nested)),g.relations.
|
|
113
|
+
push(...B.prepareUpdate(y,n,a,r.nested))),r?.rename&&(g.tables.push(...I.prepareRename(
|
|
114
|
+
y,n,r.rename)),g.constraints.push(...O.prepareRenameColumns(y,n,i.properties,r.rename))),
|
|
115
|
+
r?.remove&&(g.tables.push(I.prepareDelete(y,n,r.remove)),g.constraints.push(...O.
|
|
116
|
+
prepareDelete(y,n,r.remove))),t?.create&&T(g,w.prepareCreate(y,n,i,t.create,!0)),
|
|
117
|
+
t?.remove&&T(g,w.prepareDelete(y,n,t.remove)),o?.create&&g.relations.push(...B.prepareCreate(
|
|
118
|
+
y,n,i,o.create)),o?.remove&&g.relations.push(...B.prepareDelete(y,n,o.remove))}return d.
|
|
119
|
+
remove&&T(g,ye(d.remove)),g},"getUpdateQueries"),ye=m(e=>{let c=new L,d={tables:[],
|
|
120
|
+
constraints:[],relations:[],indexes:[]};for(let y in e){let{name:g}=e[y];d.tables.
|
|
121
|
+
push(U.prepareDelete(c,g))}return d},"getDeleteQueries"),T=m((e,c)=>{c.indexes&&
|
|
122
|
+
e.indexes.push(...c.indexes),c.constraints&&e.constraints.push(...c.constraints),
|
|
123
|
+
c.relations&&e.relations.push(...c.relations),c.tables&&e.tables.push(...c.tables)},
|
|
124
|
+
"combineMigrationQueries");export{de as getCreateQueries,ye as getDeleteQueries,ut as getUpdateQueries};
|
|
120
125
|
//# sourceMappingURL=main.mjs.map
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { PgIndexRepository } from '@ez4/pgclient/library';
|
|
2
|
+
import type { AnySchema, ObjectSchema } from '@ez4/schema';
|
|
3
|
+
import type { ObjectComparison } from '@ez4/utils';
|
|
4
|
+
import type { SqlBuilder } from '@ez4/pgsql';
|
|
5
|
+
export declare namespace ColumnQuery {
|
|
6
|
+
const prepareCreate: (builder: SqlBuilder, table: string, indexes: PgIndexRepository, columns: Record<string, AnySchema>) => {
|
|
7
|
+
query: string;
|
|
8
|
+
};
|
|
9
|
+
const prepareUpdate: (builder: SqlBuilder, table: string, schema: ObjectSchema, indexes: PgIndexRepository, changes: Record<string, ObjectComparison>) => {
|
|
10
|
+
check: string;
|
|
11
|
+
query: string;
|
|
12
|
+
}[];
|
|
13
|
+
const prepareRename: (builder: SqlBuilder, table: string, changes: Record<string, string>) => {
|
|
14
|
+
check: string;
|
|
15
|
+
query: string;
|
|
16
|
+
}[];
|
|
17
|
+
const prepareDelete: (builder: SqlBuilder, table: string, columns: Record<string, AnySchema>) => {
|
|
18
|
+
query: string;
|
|
19
|
+
};
|
|
20
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { AnySchema, ObjectSchema, ObjectSchemaProperties } from '@ez4/schema';
|
|
2
|
+
import type { ObjectComparison } from '@ez4/utils';
|
|
3
|
+
import type { SqlBuilder } from '@ez4/pgsql';
|
|
4
|
+
export declare namespace ConstraintQuery {
|
|
5
|
+
const prepareCreate: (builder: SqlBuilder, table: string, columns: Record<string, AnySchema>) => {
|
|
6
|
+
check: string;
|
|
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
|
+
})[];
|
|
16
|
+
const prepareRenameTable: (builder: SqlBuilder, fromTable: string, toTable: string, columns: Record<string, AnySchema>) => {
|
|
17
|
+
check: string;
|
|
18
|
+
query: string;
|
|
19
|
+
}[];
|
|
20
|
+
const prepareRenameColumns: (builder: SqlBuilder, table: string, columns: ObjectSchemaProperties, changes: Record<string, string>) => {
|
|
21
|
+
check: string;
|
|
22
|
+
query: string;
|
|
23
|
+
}[];
|
|
24
|
+
const prepareDelete: (builder: SqlBuilder, table: string, columns: Record<string, AnySchema>) => {
|
|
25
|
+
query: string;
|
|
26
|
+
}[];
|
|
27
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { PgIndexRepository } from '@ez4/pgclient/library';
|
|
2
|
+
import type { ObjectSchema } from '@ez4/schema';
|
|
3
|
+
import type { SqlBuilder } from '@ez4/pgsql';
|
|
4
|
+
import type { PgMigrationQueries } from '../types/query';
|
|
5
|
+
type IndexMigrationQueries = Pick<PgMigrationQueries, 'constraints' | 'indexes'>;
|
|
6
|
+
export declare namespace IndexQueries {
|
|
7
|
+
const prepareCreate: (builder: SqlBuilder, table: string, schema: ObjectSchema, indexes: PgIndexRepository, concurrent: boolean) => IndexMigrationQueries;
|
|
8
|
+
const prepareRename: (builder: SqlBuilder, fromTable: string, toTable: string, indexes: PgIndexRepository) => IndexMigrationQueries;
|
|
9
|
+
const prepareDelete: (builder: SqlBuilder, table: string, indexes: PgIndexRepository) => IndexMigrationQueries;
|
|
10
|
+
}
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { PgRelationRepository } from '@ez4/pgclient/library';
|
|
2
|
+
import type { ObjectSchema } from '@ez4/schema';
|
|
3
|
+
import type { ObjectComparison } from '@ez4/utils';
|
|
4
|
+
import type { SqlBuilder } from '@ez4/pgsql';
|
|
5
|
+
export declare namespace RelationQuery {
|
|
6
|
+
const prepareCreate: (builder: SqlBuilder, table: string, schema: ObjectSchema, relations: PgRelationRepository) => {
|
|
7
|
+
check: string;
|
|
8
|
+
query: string;
|
|
9
|
+
}[];
|
|
10
|
+
const prepareUpdate: (builder: SqlBuilder, table: string, relations: PgRelationRepository, changes: Record<string, ObjectComparison>) => any[];
|
|
11
|
+
const prepareRename: (builder: SqlBuilder, fromTable: string, toTable: string, relations: PgRelationRepository) => {
|
|
12
|
+
check: string;
|
|
13
|
+
query: string;
|
|
14
|
+
}[];
|
|
15
|
+
const prepareDelete: (builder: SqlBuilder, table: string, relations: PgRelationRepository) => {
|
|
16
|
+
query: string;
|
|
17
|
+
}[];
|
|
18
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { PgIndexRepository } from '@ez4/pgclient/library';
|
|
2
|
+
import type { ObjectSchema } from '@ez4/schema';
|
|
3
|
+
import type { SqlBuilder } from '@ez4/pgsql';
|
|
4
|
+
export declare namespace TableQuery {
|
|
5
|
+
const prepareCreate: (builder: SqlBuilder, table: string, schema: ObjectSchema, indexes: PgIndexRepository) => {
|
|
6
|
+
query: string;
|
|
7
|
+
};
|
|
8
|
+
const prepareRename: (builder: SqlBuilder, fromTable: string, toTable: string) => {
|
|
9
|
+
query: string;
|
|
10
|
+
};
|
|
11
|
+
const prepareDelete: (builder: SqlBuilder, table: string) => {
|
|
12
|
+
query: string;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { PgTableRepository } from '@ez4/pgclient/library';
|
|
2
|
-
import type { PgMigrationQueries } from '../types/query
|
|
2
|
+
import type { PgMigrationQueries } from '../types/query';
|
|
3
3
|
export declare const getCreateQueries: (target: PgTableRepository) => PgMigrationQueries;
|
|
4
4
|
export declare const getUpdateQueries: (target: PgTableRepository, source: PgTableRepository) => PgMigrationQueries;
|
|
5
5
|
export declare const getDeleteQueries: (target: PgTableRepository) => PgMigrationQueries;
|
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.27.0",
|
|
5
5
|
"author": "Silas B.",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"type": "module",
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"repository": {
|
|
12
12
|
"type": "git",
|
|
13
13
|
"url": "git+https://github.com/sbalmt/ez4.git",
|
|
14
|
-
"directory": "
|
|
14
|
+
"directory": "libraries/pgmigration"
|
|
15
15
|
},
|
|
16
16
|
"engines": {
|
|
17
17
|
"node": ">=22.7"
|
|
@@ -29,25 +29,23 @@
|
|
|
29
29
|
}
|
|
30
30
|
},
|
|
31
31
|
"workspaces": [
|
|
32
|
-
"
|
|
32
|
+
"contracts/*",
|
|
33
|
+
"libraries/*"
|
|
33
34
|
],
|
|
34
35
|
"scripts": {
|
|
35
36
|
"lint": "eslint --cache",
|
|
36
37
|
"clean": "rm -f *.tsbuildinfo && rm -rf dist/*",
|
|
37
|
-
"build": "tsc
|
|
38
|
-
"test": "npm run
|
|
39
|
-
"test:client": "npm run test:types && node --test --import ../../tools/tsnode.mjs test/client-*.spec.ts",
|
|
40
|
-
"test:only": "npm run test:types && node --test-only --test --import ../../tools/tsnode.mjs test/*.spec.ts",
|
|
41
|
-
"test:types": "npm run build && tsc -p tsconfig.test.json",
|
|
38
|
+
"build": "tsc && node tools/bundler.mjs",
|
|
39
|
+
"test": "npm run build && ez4 test",
|
|
42
40
|
"local:publish": "npm run build && npm run clean:registry && npm publish --registry http://localhost:4873",
|
|
43
41
|
"clean:registry": "rm -rf ../../.registry/@ez4/pgmigration",
|
|
44
42
|
"live:publish": "npm run build && npm publish --access public"
|
|
45
43
|
},
|
|
46
44
|
"dependencies": {
|
|
47
|
-
"@ez4/database": "^0.
|
|
48
|
-
"@ez4/pgsql": "^0.
|
|
49
|
-
"@ez4/pgclient": "^0.
|
|
50
|
-
"@ez4/schema": "^0.
|
|
51
|
-
"@ez4/utils": "^0.
|
|
45
|
+
"@ez4/database": "^0.27.0",
|
|
46
|
+
"@ez4/pgsql": "^0.27.0",
|
|
47
|
+
"@ez4/pgclient": "^0.27.0",
|
|
48
|
+
"@ez4/schema": "^0.27.0",
|
|
49
|
+
"@ez4/utils": "^0.27.0"
|
|
52
50
|
}
|
|
53
51
|
}
|
package/dist/common/columns.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { PgIndexRepository } from '@ez4/pgclient/library';
|
|
2
|
-
import type { AnySchema, ObjectSchema } from '@ez4/schema';
|
|
3
|
-
import type { ObjectComparison } from '@ez4/utils';
|
|
4
|
-
import type { SqlBuilder } from '@ez4/pgsql';
|
|
5
|
-
export declare const prepareCreateColumns: (builder: SqlBuilder, table: string, indexes: PgIndexRepository, columns: Record<string, AnySchema>) => {
|
|
6
|
-
query: string;
|
|
7
|
-
};
|
|
8
|
-
export declare const prepareUpdateColumns: (builder: SqlBuilder, table: string, schema: ObjectSchema, indexes: PgIndexRepository, changes: Record<string, ObjectComparison>) => {
|
|
9
|
-
check: string;
|
|
10
|
-
query: string;
|
|
11
|
-
}[];
|
|
12
|
-
export declare const prepareRenameColumns: (builder: SqlBuilder, table: string, changes: Record<string, string>) => {
|
|
13
|
-
check: string;
|
|
14
|
-
query: string;
|
|
15
|
-
}[];
|
|
16
|
-
export declare const prepareDeleteColumns: (builder: SqlBuilder, table: string, columns: Record<string, AnySchema>) => {
|
|
17
|
-
query: string;
|
|
18
|
-
};
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import type { AnySchema, ObjectSchema, ObjectSchemaProperties } from '@ez4/schema';
|
|
2
|
-
import type { ObjectComparison } from '@ez4/utils';
|
|
3
|
-
import type { SqlBuilder } from '@ez4/pgsql';
|
|
4
|
-
export declare const prepareCreateConstraints: (builder: SqlBuilder, table: string, columns: Record<string, AnySchema>) => {
|
|
5
|
-
check: string;
|
|
6
|
-
query: string;
|
|
7
|
-
}[];
|
|
8
|
-
export declare const prepareUpdateConstraints: (builder: SqlBuilder, table: string, targetSchema: ObjectSchema, sourceSchema: ObjectSchema, changes: Record<string, ObjectComparison>) => ({
|
|
9
|
-
query: string;
|
|
10
|
-
check?: undefined;
|
|
11
|
-
} | {
|
|
12
|
-
check: string;
|
|
13
|
-
query: string;
|
|
14
|
-
})[];
|
|
15
|
-
export declare const prepareRenameConstraints: (builder: SqlBuilder, fromTable: string, toTable: string, columns: Record<string, AnySchema>) => {
|
|
16
|
-
check: string;
|
|
17
|
-
query: string;
|
|
18
|
-
}[];
|
|
19
|
-
export declare const prepareRenameConstraintColumns: (builder: SqlBuilder, table: string, columns: ObjectSchemaProperties, changes: Record<string, string>) => {
|
|
20
|
-
check: string;
|
|
21
|
-
query: string;
|
|
22
|
-
}[];
|
|
23
|
-
export declare const prepareDeleteConstraints: (builder: SqlBuilder, table: string, columns: Record<string, AnySchema>) => {
|
|
24
|
-
query: string;
|
|
25
|
-
}[];
|
package/dist/common/indexes.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { PgIndexRepository } from '@ez4/pgclient/library';
|
|
2
|
-
import type { ObjectSchema } from '@ez4/schema';
|
|
3
|
-
import type { SqlBuilder } from '@ez4/pgsql';
|
|
4
|
-
import type { PgMigrationQueries } from '../types/query.js';
|
|
5
|
-
type IndexQueries = Pick<PgMigrationQueries, 'constraints' | 'indexes'>;
|
|
6
|
-
export declare const prepareCreateIndexes: (builder: SqlBuilder, table: string, schema: ObjectSchema, indexes: PgIndexRepository, concurrent: boolean) => IndexQueries;
|
|
7
|
-
export declare const prepareRenameIndexes: (builder: SqlBuilder, fromTable: string, toTable: string, indexes: PgIndexRepository) => IndexQueries;
|
|
8
|
-
export declare const prepareDeleteIndexes: (builder: SqlBuilder, table: string, indexes: PgIndexRepository) => IndexQueries;
|
|
9
|
-
export {};
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import type { PgRelationRepository } from '@ez4/pgclient/library';
|
|
2
|
-
import type { ObjectSchema } from '@ez4/schema';
|
|
3
|
-
import type { ObjectComparison } from '@ez4/utils';
|
|
4
|
-
import type { SqlBuilder } from '@ez4/pgsql';
|
|
5
|
-
export declare const prepareCreateRelations: (builder: SqlBuilder, table: string, schema: ObjectSchema, relations: PgRelationRepository) => {
|
|
6
|
-
check: string;
|
|
7
|
-
query: string;
|
|
8
|
-
}[];
|
|
9
|
-
export declare const prepareUpdateRelations: (builder: SqlBuilder, table: string, relations: PgRelationRepository, changes: Record<string, ObjectComparison>) => any[];
|
|
10
|
-
export declare const prepareRenameRelations: (builder: SqlBuilder, fromTable: string, toTable: string, relations: PgRelationRepository) => {
|
|
11
|
-
check: string;
|
|
12
|
-
query: string;
|
|
13
|
-
}[];
|
|
14
|
-
export declare const prepareDeleteRelations: (builder: SqlBuilder, table: string, relations: PgRelationRepository) => {
|
|
15
|
-
query: string;
|
|
16
|
-
}[];
|
package/dist/common/tables.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { PgIndexRepository } from '@ez4/pgclient/library';
|
|
2
|
-
import type { ObjectSchema } from '@ez4/schema';
|
|
3
|
-
import type { SqlBuilder } from '@ez4/pgsql';
|
|
4
|
-
export declare const prepareCreateTable: (builder: SqlBuilder, table: string, schema: ObjectSchema, indexes: PgIndexRepository) => {
|
|
5
|
-
query: string;
|
|
6
|
-
};
|
|
7
|
-
export declare const prepareRenameTable: (builder: SqlBuilder, fromTable: string, toTable: string) => {
|
|
8
|
-
query: string;
|
|
9
|
-
};
|
|
10
|
-
export declare const prepareDeleteTable: (builder: SqlBuilder, table: string) => {
|
|
11
|
-
query: string;
|
|
12
|
-
};
|