20260627165246
This commit is contained in:
1 parent
5983d29128
commit
bfb2b6037b
25 files changed
+2665
-518
No files matched your search
@@ -0,0 +1,34 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/jackc/pgx/v5"
|
||||
)
|
||||
|
||||
func main() {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||
defer cancel()
|
||||
|
||||
sqlBytes, err := os.ReadFile("db/finance_category.sql")
|
||||
must(err)
|
||||
|
||||
conn, err := pgx.Connect(ctx, "postgres://postgres:zhang520..@117.72.182.135:5432/allapp?sslmode=disable")
|
||||
must(err)
|
||||
defer conn.Close(ctx)
|
||||
|
||||
_, err = conn.Exec(ctx, string(sqlBytes))
|
||||
must(err)
|
||||
|
||||
fmt.Println("finance category schema applied")
|
||||
}
|
||||
|
||||
func must(err error) {
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/jackc/pgx/v5"
|
||||
)
|
||||
|
||||
func main() {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||
defer cancel()
|
||||
|
||||
conn, err := pgx.Connect(ctx, "postgres://postgres:zhang520..@117.72.182.135:5432/allapp?sslmode=disable")
|
||||
must(err)
|
||||
defer conn.Close(ctx)
|
||||
|
||||
rows, err := conn.Query(ctx, `
|
||||
select table_name, column_name, data_type
|
||||
from information_schema.columns
|
||||
where table_schema = 'public'
|
||||
and table_name in ('b_finance_category', 'b_finance_category_default')
|
||||
order by table_name, ordinal_position
|
||||
`)
|
||||
must(err)
|
||||
defer rows.Close()
|
||||
|
||||
for rows.Next() {
|
||||
var tableName, columnName, dataType string
|
||||
must(rows.Scan(&tableName, &columnName, &dataType))
|
||||
fmt.Printf("%s.%s %s\n", tableName, columnName, dataType)
|
||||
}
|
||||
must(rows.Err())
|
||||
}
|
||||
|
||||
func must(err error) {
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
drop table if exists b_finance_category;
|
||||
drop table if exists b_finance_category_default;
|
||||
|
||||
create table b_finance_category_default (
|
||||
id bigint primary key,
|
||||
name varchar(32) not null,
|
||||
type smallint not null,
|
||||
icon_file_key varchar(512) not null,
|
||||
icon_mime varchar(64) default '',
|
||||
sort_number int not null default 0,
|
||||
status smallint not null default 1,
|
||||
create_time timestamp,
|
||||
update_time timestamp,
|
||||
create_by bigint,
|
||||
update_by bigint
|
||||
);
|
||||
|
||||
create table b_finance_category (
|
||||
id bigint primary key,
|
||||
family_id bigint not null,
|
||||
name varchar(32) not null,
|
||||
type smallint not null,
|
||||
icon_file_key varchar(512) not null,
|
||||
icon_source smallint not null,
|
||||
icon_mime varchar(64) default '',
|
||||
sort_number int not null default 0,
|
||||
status smallint not null default 1,
|
||||
create_time timestamp,
|
||||
update_time timestamp,
|
||||
create_by bigint,
|
||||
update_by bigint
|
||||
);
|
||||
|
||||
create index idx_b_finance_category_family_status_type
|
||||
on b_finance_category (family_id, status, type, sort_number, id);
|
||||
|
||||
create index idx_b_finance_category_default_status_type
|
||||
on b_finance_category_default (status, type, sort_number, id);
|
||||
Reference in new issue
Block a user