drizzle-kit 0.9.0 → 0.9.4

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.
@@ -1,134 +0,0 @@
1
- import React, { useEffect, useState } from 'react';
2
- import { Box, Text, useInput } from 'ink';
3
-
4
- interface Props {
5
- text: React.ReactFragment;
6
- selectFrom: {missing: string, newName: string, deleted: boolean, renamed: string}[];
7
- onDone: (value: number) => void;
8
- }
9
-
10
- const SelectTable: React.FC<Props> = ({
11
- text,
12
- selectFrom,
13
- onDone,
14
- }: React.PropsWithChildren<Props>) => {
15
- const [selectedIndex, setSelectedIndex] = useState(0);
16
- const [isDone, setDone] = useState(false);
17
-
18
- useInput((input, key) => {
19
- if (key.upArrow) {
20
- const updatedIndex = selectedIndex === 0 ? selectFrom.length - 1 : selectedIndex - 1;
21
- setSelectedIndex(updatedIndex);
22
- }
23
- if (key.downArrow) {
24
- const updatedIndex = selectedIndex === (selectFrom.length - 1) ? 0 : selectedIndex + 1;
25
- setSelectedIndex(updatedIndex);
26
- }
27
-
28
- if (key.return) {
29
- setDone(true);
30
- }
31
- });
32
-
33
- useEffect(() => {
34
- if (isDone) {
35
- onDone(selectedIndex);
36
- }
37
- }, [isDone]);
38
-
39
- const prefix = (
40
- <Box flexDirection="row">
41
- <Box marginRight={1}>
42
- {isDone ? (
43
- <Text>
44
- [
45
- <Text color="green">✓</Text>
46
- ]
47
- </Text>
48
- ) : (
49
- <Text>
50
- [
51
- <Text color="gray">?</Text>
52
- ]
53
- </Text>
54
- )}
55
- </Box>
56
- <Text>
57
- {text}
58
- {' '}
59
- </Text>
60
- </Box>
61
- );
62
-
63
- return (
64
- <>
65
- <Box flexDirection={isDone ? 'row' : 'column'}>
66
- {prefix}
67
- {isDone ? (
68
- <Text>{selectedIndex}</Text>
69
- ) : (
70
- <>
71
- <Box borderStyle="single" padding={-1} width="50%">
72
- <Box width="25%">
73
- <Text>Missing</Text>
74
- </Box>
75
- <Box width="25%">
76
- <Text>| New</Text>
77
- </Box>
78
- <Box width="25%">
79
- <Text>| Deleted</Text>
80
- </Box>
81
- <Box width="25%">
82
- <Text> | Renamed</Text>
83
- </Box>
84
- </Box>
85
- {selectFrom.map(({
86
- missing, newName, deleted, renamed,
87
- }, index) => (
88
- <Box key={index} padding={0} width="50%">
89
- <Box paddingLeft={1} width="25%">
90
- <Text
91
- color={index === selectedIndex ? 'green' : 'white'}
92
- >
93
- {index === selectedIndex ? '>' : '|'}
94
- {' '}
95
- {missing}
96
- </Text>
97
- </Box>
98
- <Box width="25%">
99
- <Text
100
- color={index === selectedIndex ? 'green' : 'white'}
101
- >
102
- |
103
- {' '}
104
- {newName}
105
- </Text>
106
- </Box>
107
- <Box width="25%">
108
- <Text
109
- color={index === selectedIndex ? 'green' : 'white'}
110
- >
111
- |
112
- {' '}
113
- {deleted && '✓'}
114
- </Text>
115
- </Box>
116
- <Box width="25%">
117
- <Text
118
- color={index === selectedIndex ? 'green' : 'white'}
119
- >
120
- |
121
- {' '}
122
- {renamed || ''}
123
- </Text>
124
- </Box>
125
- </Box>
126
- ))}
127
- </>
128
- )}
129
- </Box>
130
- </>
131
- );
132
- };
133
-
134
- export default SelectTable;
package/src/index.ts DELETED
@@ -1,10 +0,0 @@
1
- import * as fs from 'fs';
2
- import Serializer from './serializer';
3
-
4
- const serializer = new Serializer();
5
-
6
- const main = () => {
7
- const resutl = serializer.generate();
8
- fs.writeFileSync('result.json', JSON.stringify(resutl, null, 2));
9
- };
10
- main();
package/src/serializer.ts DELETED
@@ -1,135 +0,0 @@
1
- /* eslint-disable no-restricted-syntax */
2
- /* eslint-disable new-cap */
3
- /* eslint-disable global-require */
4
- /* eslint-disable import/no-dynamic-require */
5
- import { AbstractTable, Column, DB } from '@lambda-team/ltdl';
6
- import ColumnType from '@lambda-team/ltdl/columns/types/columnType';
7
- import PgEnum from '@lambda-team/ltdl/columns/types/pgEnum';
8
- import TableIndex from '@lambda-team/ltdl/indexes/tableIndex';
9
- import * as fs from 'fs';
10
- import { Pool } from 'pg';
11
-
12
- interface ColumnAsObject{
13
- [name: string]:{
14
- name?: string
15
- type?: string
16
- primaryKey?: boolean
17
- autoincrement?: boolean
18
- unique?: boolean
19
- references?: {
20
- table: string,
21
- column: string
22
- }
23
- }
24
- }
25
-
26
- interface IndexColumnAsObject{
27
- [name: string]: {
28
- name?: string
29
- }
30
- }
31
-
32
- interface IndexAsObject{
33
- [name: string]:{
34
- name?: string
35
- columns?: ColumnAsObject
36
- }
37
- }
38
-
39
- interface TableAsObject {
40
- [name: string]: {
41
- name: string,
42
- columns: ColumnAsObject,
43
- indexes: {
44
- [name: string]:{
45
- name?: string
46
- type?: string
47
- }
48
- }
49
- }
50
- }
51
-
52
- interface EnumAsObject {
53
- [name: string]: {
54
- name: string,
55
- values: string[]
56
- }
57
- }
58
-
59
- export default class MigrationSerializer {
60
- public generate = () => {
61
- const result: TableAsObject = {};
62
- const filenames = fs.readdirSync('./examples/tables/');
63
-
64
- const enumToReturn: EnumAsObject = {};
65
-
66
- filenames.forEach((filename) => {
67
- const table = this.fromFile(`../examples/tables/${filename.split('.')[0]}`);
68
- const tableValues = Object.entries(table);
69
-
70
- const columnToReturn: ColumnAsObject = {};
71
- const indexToReturn: IndexAsObject = {};
72
-
73
- for (const properties of tableValues) {
74
- const key = properties[0];
75
- const value = properties[1];
76
- if (value instanceof TableIndex) {
77
- const columns = value.getColumns();
78
- const name = value.indexName();
79
-
80
- const indexColumnToReturn: IndexColumnAsObject = {};
81
-
82
- for (const column of columns) {
83
- const columnName = column.getColumnName();
84
- indexColumnToReturn[columnName] = {
85
- name: columnName,
86
- };
87
- }
88
-
89
- indexToReturn[name] = {
90
- name,
91
- columns: indexColumnToReturn,
92
- };
93
- }
94
- if (value instanceof Column) {
95
- const columnType = value.getColumnType();
96
- if (columnType instanceof PgEnum) {
97
- const enumValues = Object.values(columnType.codeType) as string[];
98
- enumToReturn[columnType.getDbName()] = {
99
- name: columnType.getDbName(),
100
- values: enumValues,
101
- };
102
- }
103
- columnToReturn[key] = {
104
- name: value.getColumnName(),
105
- type: (value.getColumnType() as ColumnType).getDbName(),
106
- primaryKey: !!value.primaryKeyName,
107
- autoincrement: value.isAutoIncrement(),
108
- unique: !!value.uniqueKeyName,
109
- };
110
- const referenced = value.getReferenced();
111
- if (referenced){
112
- columnToReturn[key].references = {
113
- table: referenced.getParentName(),
114
- column: referenced.getColumnName()
115
- }
116
- }
117
- }
118
- }
119
-
120
- result[table.tableName()] = {
121
- name: table.tableName(),
122
- columns: columnToReturn,
123
- indexes: indexToReturn,
124
- };
125
- });
126
-
127
- return { version: '1', tables: result, enums: enumToReturn };
128
- };
129
-
130
- private fromFile(filepath: string): AbstractTable<any> {
131
- const db = new DB(new Pool());
132
- const importedTable = require(filepath);
133
- return (new importedTable.default(db) as AbstractTable<any>);
134
- }
135
- }
package/tsconfig.json DELETED
@@ -1,28 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "es2020",
4
- "lib": ["es2020"],
5
- "allowJs": false,
6
- "skipLibCheck": false,
7
- "esModuleInterop": true,
8
- "allowSyntheticDefaultImports": true,
9
- "strict": true,
10
- "noImplicitOverride": true,
11
- "forceConsistentCasingInFileNames": true,
12
- "module": "commonjs",
13
- "moduleResolution": "node",
14
- "resolveJsonModule": true,
15
- "isolatedModules": true,
16
- "jsx": "react",
17
- "sourceMap": true,
18
- "baseUrl": "./src",
19
- "paths": {
20
- "@common/*": [
21
- "./common/*"
22
- ],
23
- "@utils/*": [
24
- "./utils/*"
25
- ]
26
- }
27
- }
28
- }
package/webpack.config.js DELETED
@@ -1,56 +0,0 @@
1
- const path = require('path');
2
- const webpack = require('webpack');
3
- const { TsconfigPathsPlugin } = require('tsconfig-paths-webpack-plugin');
4
- const nodeExternals = require('webpack-node-externals');
5
- const ShebangPlugin = require('webpack-shebang-plugin');
6
-
7
- const isProd = process.env.NODE_ENV === 'production';
8
-
9
- module.exports = {
10
- entry: {
11
- sj: './src/cli/index.tsx',
12
- },
13
- output: {
14
- path: path.resolve(__dirname, 'dist'),
15
- filename: '[name].js',
16
- clean: true,
17
- },
18
- mode: isProd ? 'production' : 'development',
19
- externalsPresets: {
20
- node: true,
21
- },
22
- externals: [nodeExternals()],
23
- devtool: isProd ? 'source-map' : 'inline-source-map',
24
- module: {
25
- rules: [
26
- {
27
- test: /\.js$/,
28
- loader: 'source-map-loader',
29
- enforce: 'pre',
30
- },
31
- {
32
- test: /\.tsx?$/,
33
- use: {
34
- loader: 'ts-loader',
35
- // options: {
36
- // onlyCompileBundledFiles: true,
37
- // },
38
- },
39
- exclude: /node_modules/,
40
- },
41
- ],
42
- },
43
- plugins: [
44
- new webpack.WatchIgnorePlugin({
45
- paths: [/\.js$/, /\.d\.ts$/],
46
- }),
47
- new ShebangPlugin(),
48
- ],
49
- resolve: {
50
- extensions: ['.js', '.ts', '.tsx'],
51
- plugins: [new TsconfigPathsPlugin()],
52
- },
53
- watchOptions: {
54
- ignored: /node_modules/,
55
- },
56
- };