1
1
mirror of https://github.com/wader/fq.git synced 2024-12-19 19:31:37 +03:00
fq/format/postgres/pg_control.go

172 lines
4.9 KiB
Go
Raw Normal View History

2022-07-19 08:58:31 +03:00
package postgres
import (
2022-09-23 13:50:54 +03:00
"embed"
2022-10-05 19:37:42 +03:00
2022-07-19 08:58:31 +03:00
"github.com/wader/fq/format"
"github.com/wader/fq/format/postgres/common"
2022-10-05 13:16:39 +03:00
"github.com/wader/fq/format/postgres/flavours/pgpro10"
2022-08-26 14:55:06 +03:00
"github.com/wader/fq/format/postgres/flavours/pgpro11"
2022-08-26 12:12:22 +03:00
"github.com/wader/fq/format/postgres/flavours/pgpro12"
2022-08-26 09:41:34 +03:00
"github.com/wader/fq/format/postgres/flavours/pgpro13"
2022-08-05 09:05:55 +03:00
"github.com/wader/fq/format/postgres/flavours/pgpro14"
"github.com/wader/fq/format/postgres/flavours/pgproee10"
2022-08-02 17:20:50 +03:00
"github.com/wader/fq/format/postgres/flavours/pgproee11"
"github.com/wader/fq/format/postgres/flavours/pgproee12"
"github.com/wader/fq/format/postgres/flavours/pgproee13"
2022-07-20 09:29:46 +03:00
"github.com/wader/fq/format/postgres/flavours/pgproee14"
2023-05-03 15:28:29 +03:00
"github.com/wader/fq/format/postgres/flavours/pgproee15"
2022-10-05 13:16:39 +03:00
"github.com/wader/fq/format/postgres/flavours/postgres10"
2022-07-20 08:43:24 +03:00
"github.com/wader/fq/format/postgres/flavours/postgres11"
2022-08-03 13:40:31 +03:00
"github.com/wader/fq/format/postgres/flavours/postgres12"
"github.com/wader/fq/format/postgres/flavours/postgres13"
2022-07-20 08:43:24 +03:00
"github.com/wader/fq/format/postgres/flavours/postgres14"
2022-07-19 08:58:31 +03:00
"github.com/wader/fq/pkg/decode"
"github.com/wader/fq/pkg/interp"
)
2022-09-23 13:50:54 +03:00
//go:embed pg_control.md
var pgControlFS embed.FS
2022-07-19 08:58:31 +03:00
func init() {
2023-05-04 08:45:42 +03:00
interp.RegisterFormat(format.Pg_Control, &decode.Format{
2022-07-19 12:00:00 +03:00
Description: "PostgreSQL control file",
2022-07-19 08:58:31 +03:00
DecodeFn: decodePgControl,
2023-05-04 08:45:42 +03:00
DefaultInArg: format.Pg_Control_In{
Flavour: "",
2022-07-20 08:43:24 +03:00
},
2022-07-19 08:58:31 +03:00
})
2022-09-23 13:50:54 +03:00
interp.RegisterFS(pgControlFS)
2022-07-19 08:58:31 +03:00
}
const (
PG_CONTROL_VERSION_10 = 1002
PG_CONTROL_VERSION_11 = 1100
PGPRO_CONTROL_VERSION_11 = 1200
PG_CONTROL_VERSION_12 = 1201
//PG_CONTROL_VERSION_13 = 1300
2022-07-19 08:58:31 +03:00
PG_CONTROL_VERSION_14 = 1300
//PG_CONTROL_VERSION_15 = 1300
2022-07-19 08:58:31 +03:00
)
2022-07-20 08:43:24 +03:00
const (
2022-10-05 13:16:39 +03:00
PG_FLAVOUR_POSTGRES10 = "postgres10"
2022-07-20 08:43:24 +03:00
PG_FLAVOUR_POSTGRES11 = "postgres11"
2022-08-03 13:40:31 +03:00
PG_FLAVOUR_POSTGRES12 = "postgres12"
PG_FLAVOUR_POSTGRES13 = "postgres13"
2022-07-20 08:43:24 +03:00
PG_FLAVOUR_POSTGRES14 = "postgres14"
2023-04-17 17:12:46 +03:00
PG_FLAVOUR_POSTGRES15 = "postgres15"
2022-10-05 13:16:39 +03:00
PG_FLAVOUR_PGPRO10 = "pgpro10"
2022-08-26 14:55:06 +03:00
PG_FLAVOUR_PGPRO11 = "pgpro11"
2022-08-26 12:12:22 +03:00
PG_FLAVOUR_PGPRO12 = "pgpro12"
2022-08-26 09:41:34 +03:00
PG_FLAVOUR_PGPRO13 = "pgpro13"
2022-08-05 09:05:55 +03:00
PG_FLAVOUR_PGPRO14 = "pgpro14"
2023-04-17 17:12:46 +03:00
PG_FLAVOUR_PGPRO15 = "pgpro15"
PG_FLAVOUR_PGPROEE10 = "pgproee10"
2022-08-02 16:40:12 +03:00
PG_FLAVOUR_PGPROEE11 = "pgproee11"
PG_FLAVOUR_PGPROEE12 = "pgproee12"
PG_FLAVOUR_PGPROEE13 = "pgproee13"
2022-07-20 09:29:46 +03:00
PG_FLAVOUR_PGPROEE14 = "pgproee14"
2023-04-17 17:12:46 +03:00
PG_FLAVOUR_PGPROEE15 = "pgproee15"
2022-07-20 08:43:24 +03:00
)
2023-05-03 09:45:25 +03:00
func decodePgControl(d *decode.D) any {
2022-07-19 08:58:31 +03:00
d.Endian = decode.LittleEndian
2023-05-04 08:45:42 +03:00
var pgIn format.Pg_Control_In
2023-05-03 09:45:25 +03:00
if !d.ArgAs(&pgIn) {
d.Fatalf("no flavour specified")
2022-09-06 12:55:15 +03:00
}
switch pgIn.Flavour {
2022-10-05 13:16:39 +03:00
case PG_FLAVOUR_POSTGRES10:
2023-05-03 09:45:25 +03:00
return postgres10.DecodePgControl(d)
2022-07-20 08:43:24 +03:00
case PG_FLAVOUR_POSTGRES11:
2023-05-03 09:45:25 +03:00
return postgres11.DecodePgControl(d)
2022-08-03 13:40:31 +03:00
case PG_FLAVOUR_POSTGRES12:
2023-05-03 09:45:25 +03:00
return postgres12.DecodePgControl(d)
case PG_FLAVOUR_POSTGRES13:
2023-05-03 09:45:25 +03:00
return postgres13.DecodePgControl(d)
2023-04-17 17:12:46 +03:00
case PG_FLAVOUR_POSTGRES14, PG_FLAVOUR_POSTGRES15, PG_FLAVOUR_PGPRO15:
2023-05-03 09:45:25 +03:00
return postgres14.DecodePgControl(d)
2022-10-05 13:16:39 +03:00
case PG_FLAVOUR_PGPRO10:
2023-05-03 09:45:25 +03:00
return pgpro10.DecodePgControl(d)
2022-08-26 14:55:06 +03:00
case PG_FLAVOUR_PGPRO11:
2023-05-03 09:45:25 +03:00
return pgpro11.DecodePgControl(d)
2022-08-26 12:12:22 +03:00
case PG_FLAVOUR_PGPRO12:
2023-05-03 09:45:25 +03:00
return pgpro12.DecodePgControl(d)
2022-08-26 09:41:34 +03:00
case PG_FLAVOUR_PGPRO13:
2023-05-03 09:45:25 +03:00
return pgpro13.DecodePgControl(d)
2022-08-05 09:05:55 +03:00
case PG_FLAVOUR_PGPRO14:
2023-05-03 09:45:25 +03:00
return pgpro14.DecodePgControl(d)
case PG_FLAVOUR_PGPROEE10:
2023-05-03 09:45:25 +03:00
return pgproee10.DecodePgControl(d)
2022-08-02 17:20:50 +03:00
case PG_FLAVOUR_PGPROEE11:
2023-05-03 09:45:25 +03:00
return pgproee11.DecodePgControl(d)
case PG_FLAVOUR_PGPROEE12:
2023-05-03 09:45:25 +03:00
return pgproee12.DecodePgControl(d)
case PG_FLAVOUR_PGPROEE13:
2023-05-03 09:45:25 +03:00
return pgproee13.DecodePgControl(d)
2022-07-20 09:29:46 +03:00
case PG_FLAVOUR_PGPROEE14:
2023-05-03 09:45:25 +03:00
return pgproee14.DecodePgControl(d)
2023-04-17 17:12:46 +03:00
case PG_FLAVOUR_PGPROEE15:
2023-05-03 09:45:25 +03:00
return pgproee15.DecodePgControl(d)
2022-07-20 08:43:24 +03:00
default:
break
}
2023-05-03 09:45:25 +03:00
return probeForDecode(d)
2022-07-20 08:43:24 +03:00
}
2023-05-03 09:45:25 +03:00
func probeForDecode(d *decode.D) any {
2022-07-19 08:58:31 +03:00
/* 0 | 8 */ // uint64 system_identifier;
/* 8 | 4 */ // uint32 pg_control_version;
2022-07-19 12:00:00 +03:00
d.U64()
pgControlVersion := d.U32()
2022-09-06 09:27:04 +03:00
d.SeekAbs(0)
2022-07-19 08:58:31 +03:00
pgProVersion, oriVersion := common.ParsePgProVersion(uint32(pgControlVersion))
if pgProVersion == common.PG_ORIGINAL {
switch oriVersion {
2022-10-05 13:16:39 +03:00
case PG_CONTROL_VERSION_10:
2023-05-03 09:45:25 +03:00
return postgres10.DecodePgControl(d)
case PG_CONTROL_VERSION_11:
2023-05-03 09:45:25 +03:00
return postgres11.DecodePgControl(d)
case PG_CONTROL_VERSION_12:
2023-05-03 09:45:25 +03:00
return postgres12.DecodePgControl(d)
case PG_CONTROL_VERSION_14:
2023-05-03 09:45:25 +03:00
return postgres14.DecodePgControl(d)
}
2022-07-19 08:58:31 +03:00
}
if pgProVersion == common.PGPRO_STANDARD {
switch oriVersion {
2022-10-05 13:16:39 +03:00
case PG_CONTROL_VERSION_10:
2023-05-03 09:45:25 +03:00
return pgpro10.DecodePgControl(d)
case PG_CONTROL_VERSION_11:
2023-05-03 09:45:25 +03:00
return pgpro11.DecodePgControl(d)
case PG_CONTROL_VERSION_12:
2023-05-03 09:45:25 +03:00
return pgpro12.DecodePgControl(d)
case PG_CONTROL_VERSION_14:
2023-05-03 09:45:25 +03:00
return pgpro14.DecodePgControl(d)
}
}
if pgProVersion == common.PGPRO_ENTERPRISE {
switch oriVersion {
case PG_CONTROL_VERSION_10:
2023-05-03 09:45:25 +03:00
return pgproee10.DecodePgControl(d)
case PGPRO_CONTROL_VERSION_11:
2023-05-03 09:45:25 +03:00
return pgproee11.DecodePgControl(d)
case PG_CONTROL_VERSION_12:
2023-05-03 09:45:25 +03:00
return pgproee12.DecodePgControl(d)
case PG_CONTROL_VERSION_14:
2023-05-03 09:45:25 +03:00
return pgproee14.DecodePgControl(d)
}
}
d.Fatalf("unsupported PG_CONTROL_VERSION = %d", pgControlVersion)
2022-07-19 08:58:31 +03:00
return nil
}